{"id":7,"date":"2005-02-02T23:48:00","date_gmt":"2005-02-02T23:48:00","guid":{"rendered":"http:\/\/blog.trungson.com\/?p=7"},"modified":"2005-02-02T23:48:00","modified_gmt":"2005-02-02T23:48:00","slug":"get-ip-information-from-caida-netgeo","status":"publish","type":"post","link":"http:\/\/blog.trungson.com\/?p=7","title":{"rendered":"Get IP information from CAIDA NetGeo"},"content":{"rendered":"<p>Note that CAIDA NetGeo is no longer active and its database is not accurate (could be very inaccurate!).<br \/>\n<textarea name=\"code\" class=\"php\"><br \/>\n<?php\n$ip = getenv(\"REMOTE_ADDR\");\n$hostname = gethostbyaddr($ip);\n$target = $ip;\n$url = \"http:\/\/netgeo.caida.org\/perl\/netgeo.cgi?method=getRecord&#038;nonblocking=true&#038;target=$target\";\n$handle = fopen ($url, \"r\");\n$buffer = \"\";\nwhile (!feof ($handle)) {\n    $buffer .= fgets($handle, 4096);\n}\n$buffer = strip_tags($buffer);\n$bufferAry = explode(\"\\n\",$buffer);\n$bufferAry = array_slice($bufferAry,5);\n$buffer = implode(\"\\n\",$bufferAry);\nfclose ($handle);\n\necho(\"Your IP is <b>$ip<\/b>, resolved hostname is <i><b>$hostname<\/b><\/i> &#8220;);<br \/>\necho(&#8220;and NetGeo, a public database that associates IP addresses to geographical information, &#8220;);<br \/>\necho(&#8220;gives the following details:<br \/>\\n&#8221;);<br \/>\necho(&#8220;<\/p>\n<form>&#8220;);<br \/>\necho(&#8220;<text\".\"area rows=\\\"15\\\" cols=\\\"60\\\">$buffer<\/text\".\"area><br \/>&#8220;);<br \/>\necho(&#8220;<\/form>\n<p>&#8220;);<br \/>\necho(&#8220;<i>Courtesy of caida.org<\/i>&#8220;);<\/p>\n<p>?><br \/>\n<\/textarea><\/p>\n<p>Sample Output<\/p>\n<pre>\nTARGET:        67.180.238.xx\nNAME:          IANA-NETBLOCK-67\nNUMBER:        67.0.0.0 - 67.255.255.255\nCITY:          \nSTATE:         \nCOUNTRY:       AU\nLAT:           -25.00\nLONG:          135.00\nLAT_LONG_GRAN: Country\nLAST_UPDATED:  \nNIC:           APNIC\nLOOKUP_TYPE:   Block Allocation\nRATING:        \nDOMAIN_GUESS:  apnic.net\nSTATUS:        OK\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Note that CAIDA NetGeo is no longer active and its database is not accurate (could be very inaccurate!).<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/posts\/7"}],"collection":[{"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7"}],"version-history":[{"count":0,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/posts\/7\/revisions"}],"wp:attachment":[{"href":"http:\/\/blog.trungson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}