Quote:
Originally Posted by frih
a free whois script, i need it. 
|
What do you need?
Heres a whois script i made to get the country of an IP. ( works on Unix systems with PHP )
PHP Code:
$ip = $_SERVER['REMOTE_ADDR'];
//$country = exec('whois .'$ip.' | grep -i country');
$country = exec("whois $ip | grep -i country"); // Run a local whois
$country = strtolower($country);
// Get rid of ****
$country = str_replace("country:", "", "$country"); // replace **** so we just have the CC
$country = str_replace("Country:", "", "$country");
$country = str_replace("Country :", "", "$country");
$country = str_replace("country :", "", "$country");
$country = str_replace("network:country-code:", "", "$country"); // Where teh **** is this coming from? Odd whois...
$country = str_replace("network:Country-Code:", "", "$country"); // Where teh **** is this coming from? Odd whois...
$country = str_replace("Network:Country-Code:", "", "$country"); // Where teh **** is this coming from? Odd whois...
$country = str_replace("network:organization-", "", "$country"); // Where teh **** is this coming from? Odd whois...
$country = str_replace("network:organization-usa", "", "$country");
// End get rid of.
$country = str_replace(" ", "", "$country");
$country should now contain the country code. IE:
print $country;
UK
Looking at my code again, I str2lowered it, so this will do the same with less guff
PHP Code:
$ip = $_SERVER['REMOTE_ADDR'];
//$country = exec('whois .'$ip.' | grep -i country');
$country = exec("whois $ip | grep -i country"); // Run a local whois
$country = strtolower($country);
// Get rid of ****
$country = str_replace("country:", "", "$country"); // replace **** so we just have the CC
$country = str_replace("country :", "", "$country");
$country = str_replace("network:country-code:", "", "$country"); // Where teh **** is this coming from? Odd whois...
$country = str_replace("network:organization-", "", "$country"); // Where teh **** is this coming from? Odd whois...
$country = str_replace("network:organization-usa", "", "$country");
// End get rid of.
$country = str_replace(" ", "", "$country");