
-----------------------------------
Amailer
Sat Mar 27, 2004 6:42 pm

Get country by ip
-----------------------------------




hehe, hmm anoying lil script but i think it works atlast.. if anyone can find a bug please tell me... i need to fix it fast then.

-----------------------------------
Amailer
Sat Mar 27, 2004 7:33 pm


-----------------------------------
help..


//
// Get the ips ISP
//
function rwhois($ip='') {

$ident = $ip;
if ($fp = fsockopen("whois.arin.net", 43))
{
    fputs($fp, "{$ident}\r\n");
    while (!feof($fp)) {
		$content[] = fgets($fp);
	}

	for($i=0; $i < count($content); $i++) {

		if(eregi('Country: ', $content[$i])) {
			$country = $content[$i];
			$content[$i] = str_replace('Country: ', '', $content[$i]);
		  
			$value = $content[$i] . '';
   
			return $value;
		}
	}
		if(!isset($value)) {
			$no = true;
		} else {
			$no = false;
		}
	

 if($no == true) {
   $longisp = @gethostbyaddr($ip);
   $isp = explode('.', $longisp);
   $isp = array_reverse($isp);
   $tmp = $isp[1];
   if (preg_match("/\/i", $tmp)) {
       $myisp = $isp[2].'.'.$isp[1].'.'.$isp[0];
   } else {
       $myisp = $isp[1].'.'.$isp[0];
   }
   if (preg_match("/[0-9]{1,3}\.[0-9]{1,3}/", $myisp))
     return false;
   $value = $myisp;

   $value = array_pop(explode(".", $value));

   return $value;

   }

}


}
    
//
// Check if ip is valid
//
function is_ip($ip) {
$valid = TRUE;

if(preg_match("/^((127)|(192)|(10).*)$/", "$ip")) {
    return FALSE;
    }

$ip = explode(".", $ip);
    if(count($ip)!=4) {
        return FALSE;
        }
    foreach($ip as $block) {
        if(!is_numeric($block) || $block>255 || $block