Revisando
este post encontré este código:
Código PHP:
<?
global $REMOTE_HOST, $REMOTE_ADDR, $HTTP_X_FORWARDED_FOR, $MIRRORS;
// We do not know the country
$country = '';
// Figure out IP address and hostname
$ipaddr = $HTTP_X_FORWARDED_FOR ? $HTTP_X_FORWARDED_FOR : $REMOTE_ADDR;
$hostname = $REMOTE_HOST;
// If we have no hostname, or if it's an IP
// address, then try to get that hostname
if (!$hostname || $hostname == $ipaddr) {
$hostname = @gethostbyaddr($ipaddr);
if ($hostname == $ipaddr) { $hostname = ""; }
}
// If we have that hostname finnaly, get the TLD
if ($hostname) {
if (ereg('([a-zA-Z]+)$', $hostname, $reg)) {
$country = $reg[0];
}
}
?>
Lo saqué del código de
http://www.php.net