Here is my 5th Code:
By this class you can have many informations about an IP address:


CODE
<?php
class ipinfo
{
    var $remote_addr;
    var $address;
    var $country;
    var $state;
    var $city;
    var $isp;
    var $organization;
    
    function ipinfo()
    {
        $this->remote_addr = $_SERVER["REMOTE_ADDR"];
    }
    
    function check($ip = false)
    {
        if ($ip == false)
        $ip = $this->remote_addr;

        $postfields = "custom_ip_address=".urlencode($ip)."&submit=".urlencode("lookup any ip");
        
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, 'http://www.ip-adress.com/index.php');
        curl_setopt($ch, CURLOPT_HEADER, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
        curl_setopt($ch, CURLOPT_REFERER, "http://www.ip-adress.com");
        //curl_setopt($ch, CURLOPT_PROXY, '211.233.74.24:80'); //To use proxy!
        $html = curl_exec($ch);
        curl_close($ch);
                
        if($html)
        {
            $start = strpos($html, '</form>');
            $end = strpos($html, '<p align="left"></p>') - $start;
            
            $html2 = trim(substr($html, $start, $end));
            $html2 = trim(ereg_replace("<([^>]+)>", "", $html2));
            $html2 = ereg_replace("\n", "<br>", $html2);
            
            $html3 = explode("<br>", $html2);
            
            /* //If you want to use arrays
            $ipinfo = array();
            $ipinfo["address"] = trim($html3[1]);
            $ipinfo["country"] = trim($html3[10]);
            $ipinfo["state"] = trim($html3[15]);
            $ipinfo["city"] = trim($html3[19]);
            $ipinfo["isp"] = trim($html3[31]);
            $ipinfo["organization"] = trim($html3[35]);
            $this->ipinfo = $ipinfo;
            */
            
            $this->address = trim($html3[1]);
            $this->country = trim($html3[10]);
            $this->state = trim($html3[15]);
            $this->city = trim($html3[19]);
            $this->isp = trim($html3[31]);
            $this->organization = trim($html3[35]);
        }
    }
}

$ipinfo = new ipinfo;

echo "<b>Check my IP:</b><br><br>";
$ipinfo->check();

echo    "IP Address: ".$ipinfo->address;
echo    "<br>Country: ".$ipinfo->country;
echo    "<br>State: ".$ipinfo->state;
echo    "<br>City: ".$ipinfo->city;
echo    "<br>ISP :".$ipinfo->isp;
echo    "<br> Organization :".$ipinfo->organization."<br><br><br>";

echo "<b>Check custom IP:</b><br><br>";
$ipinfo->check("72.14.221.99");

echo    "IP Address: ".$ipinfo->address;
echo    "<br>Country: ".$ipinfo->country;
echo    "<br>State: ".$ipinfo->state;
echo    "<br>City: ".$ipinfo->city;
echo    "<br>ISP :".$ipinfo->isp;
echo    "<br> Organization :".$ipinfo->organization;

?>

 

 

 


Reply