Ниже приведен код функции, возвращающей страну по ip адресу:

Код:
function country_by_ip ($ip)
{
$sock = fsockopen ("whois.ripe.net", 43, $errno, $errstr);
if (!$sock)
{
return "??";
}
else
{
fputs($sock, $ip."\r\n"); // Здесь ошибка?
while (!feof($sock))
{
$str=fgets ($sock, 128);
//echo $str; // И видим, что что-то не так с fputs
$country=substr(strstr($str,"country:"), 8);
if ($country)
{
$country=trim($country);
$country=substr($country, 0, 2);
return strtoupper($country);
}
}
return "??";
}
fclose ($sock);
}
Эта функция возвразает EU (Европу) (!?) вместо UA, RU или PL. Причем год назад все работало.
Кто знает - просьба помочь. Нужно, чтобы возвращались страны (UA, RU, PL).