Skip to content

Instantly share code, notes, and snippets.

@paddya
Created October 30, 2011 19:54
Show Gist options
  • Save paddya/1326352 to your computer and use it in GitHub Desktop.
Save paddya/1326352 to your computer and use it in GitHub Desktop.
function ip2country($ipv4) {
$sock = fsockopen("whois.ripe.net", 43);
fwrite($sock, $ipv4."\n");
$info = '';
while (!feof($sock)) {
$info .= fgetc($sock);
}
fclose($sock);
preg_match("/country:[ ]+([A-Z]{2})\n/", $info, $match);
if(isset($match[1]))
return $match[1];
else
return 'n/a';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment