{"id":373,"date":"2009-11-04T17:44:17","date_gmt":"2009-11-04T10:44:17","guid":{"rendered":"http:\/\/www.icez.net\/blog\/?p=373"},"modified":"2010-06-16T18:53:45","modified_gmt":"2010-06-16T11:53:45","slug":"geodns-for-bind-9-2","status":"publish","type":"post","link":"https:\/\/www.icez.net\/blog\/373\/geodns-for-bind-9-2","title":{"rendered":"0083 | GeoDNS for BIND 9.2+"},"content":{"rendered":"<p>\u0e40\u0e2d\u0e32\u0e44\u0e27\u0e49\u0e17\u0e33 CDN \u0e44\u0e14\u0e49\u0e04\u0e23\u0e31\u0e1a \u0e43\u0e2b\u0e49 dns lookup \u0e2d\u0e2d\u0e01\u0e21\u0e32\u0e15\u0e32\u0e21\u0e1b\u0e23\u0e30\u0e40\u0e17\u0e28<\/p>\n<p>shell script (\u0e08\u0e33\u0e17\u0e35\u0e48\u0e21\u0e32\u0e44\u0e21\u0e48\u0e44\u0e14\u0e49 \u0e02\u0e2d\u0e2d\u0e20\u0e31\u0e22\u0e14\u0e49\u0e27\u0e22\u0e04\u0e23\u0e31\u0e1a)<\/p>\n<pre lang=\"bash\">\r\n#!\/bin\/bash\r\ncd \/tmp\r\n\/bin\/rm -f GeoIPCountryCSV.zip\r\nwget -T 5 -t 1 http:\/\/geolite.maxmind.com\/download\/geoip\/database\/GeoIPCountryCSV.zip\r\nunzip GeoIPCountryCSV.zip || exit 1\r\n\r\necho -n \"Creating CNM (Country,Net\/Mask) CSV file...\"\r\nawk -F \\\" 'function s(c,b,e,l,m,n) {l = log(e-b+1)\/log(2); m = 2^32-2^int(l); n = and(m,e); if (n == and(m,b)) {printf \"%s,%u.%u.%u.%u\/%u\\n\",c,b\/2^24%256,b\/2^16%256,b\/2^8%256,b%256,32-l} else {s(c,b,n-1); s(c,n,e)}} s($10,$6,$8)' GeoIPCountryWhois.csv > cnm.csv\r\nrm -f GeoIPCountryWhois.csv\r\necho -ne \"DONE\\nGenerating BIND GeoIP.acl file...\"\r\n\r\n(for c in $(awk -F , '{print $1}' cnm.csv | sort -u)\r\ndo\r\n  echo \"acl \\\"$c\\\" {\"\r\n  grep \"^$c,\" cnm.csv | awk -F , '{print \"\\t\"$2\";\"}'\r\n  echo -e \"};\\n\"\r\ndone) > \/etc\/named.GeoIP.acl\r\n\r\nrm -f cnm.csv\r\necho \"DONE\"\r\n\r\n\/etc\/init.d\/named reload\r\n\r\nexit 0\r\n<\/pre>\n<p>\u0e41\u0e25\u0e49\u0e27\u0e44\u0e1b\u0e41\u0e01\u0e49 named.conf<\/p>\n<pre lang=\"apache\">\r\ninclude \"\/etc\/named.GeoIP.acl\";\r\nview \"thailand\" {\r\n    match-clients { TH; };\r\n        match-clients { TH; };\r\n        zone \"upic.me\" {\r\n                type master;\r\n                file \"master\/th.db.upic.me\";\r\n        };\r\n}\r\nview \"inter\" {\r\n        match-clients { any; };\r\n        zone \"upic.me\" {\r\n                type master;\r\n                file \"master\/all.db.upic.me\";\r\n        };\r\n};\r\n<\/pre>\n<p>\u0e2d\u0e22\u0e32\u0e01\u0e44\u0e14\u0e49\u0e1b\u0e23\u0e30\u0e40\u0e17\u0e28\u0e44\u0e2b\u0e19\u0e01\u0e47\u0e25\u0e2d\u0e07\u0e14\u0e39 code \u0e43\u0e19\u0e44\u0e1f\u0e25\u0e4c \/etc\/named.GeoIP.acl \u0e25\u0e30\u0e01\u0e31\u0e19\u0e04\u0e23\u0e31\u0e1a<br \/>\n\u0e2a\u0e48\u0e27\u0e19&#8230; script \u0e14\u0e49\u0e32\u0e19\u0e1a\u0e19<br \/>\n\u0e40\u0e0b\u0e1f\u0e41\u0e25\u0e49\u0e27\u0e40\u0e2d\u0e32\u0e43\u0e2a\u0e48\u0e43\u0e19 cron \u0e14\u0e49\u0e27\u0e22\u0e40\u0e25\u0e22\u0e08\u0e30\u0e14\u0e35\u0e21\u0e32\u0e01 \u0e23\u0e31\u0e19\u0e2a\u0e31\u0e1b\u0e14\u0e32\u0e2b\u0e4c\u0e25\u0e30\u0e04\u0e23\u0e31\u0e49\u0e07<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0e40\u0e2d\u0e32\u0e44\u0e27\u0e49\u0e17\u0e33 CDN \u0e44\u0e14\u0e49\u0e04\u0e23\u0e31\u0e1a \u0e43\u0e2b\u0e49 dns lookup \u0e2d\u0e2d\u0e01\u0e21\u0e32\u0e15\u0e32\u0e21\u0e1b\u0e23\u0e30\u0e40\u0e17\u0e28 shell script (\u0e08\u0e33\u0e17\u0e35\u0e48\u0e21\u0e32\u0e44\u0e21\u0e48\u0e44\u0e14\u0e49 \u0e02\u0e2d\u0e2d\u0e20\u0e31\u0e22\u0e14\u0e49\u0e27\u0e22\u0e04\u0e23\u0e31\u0e1a) #!\/bin\/bash cd \/tmp \/bin\/rm -f GeoIPCountryCSV.zip wget -T 5 -t 1 http:\/\/geolite.maxmind.com\/download\/geoip\/database\/GeoIPCountryCSV.zip unzip GeoIPCountryCSV.zip || exit 1 echo -n &#8220;Creating CNM (Country,Net\/Mask) CSV file&#8230;&#8221; awk -F \\&#8221; &#8216;function s(c,b,e,l,m,n) {l = log(e-b+1)\/log(2); m = 2^32-2^int(l); n = and(m,e); if (n == and(m,b)) {printf &#8220;%s,%u.%u.%u.%u\/%u\\n&#8221;,c,b\/2^24%256,b\/2^16%256,b\/2^8%256,b%256,32-l} [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,50],"tags":[97,99,12,98],"class_list":["post-373","post","type-post","status-publish","format-standard","hentry","category-network","category-linux","tag-bind","tag-cdn","tag-dns","tag-geodns"],"_links":{"self":[{"href":"https:\/\/www.icez.net\/blog\/wp-json\/wp\/v2\/posts\/373","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.icez.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.icez.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.icez.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.icez.net\/blog\/wp-json\/wp\/v2\/comments?post=373"}],"version-history":[{"count":3,"href":"https:\/\/www.icez.net\/blog\/wp-json\/wp\/v2\/posts\/373\/revisions"}],"predecessor-version":[{"id":683,"href":"https:\/\/www.icez.net\/blog\/wp-json\/wp\/v2\/posts\/373\/revisions\/683"}],"wp:attachment":[{"href":"https:\/\/www.icez.net\/blog\/wp-json\/wp\/v2\/media?parent=373"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.icez.net\/blog\/wp-json\/wp\/v2\/categories?post=373"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.icez.net\/blog\/wp-json\/wp\/v2\/tags?post=373"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}