Need help with PHP script for IP address of sites

phpasks

New Member
Messages
145
Reaction score
0
Points
0
Need help with PHP script for IP address of sites

Hi All
I need some assistance with getting the IP address of a web site.

Basically I have to write a PHP page where if a site name is supplied it would return back the IP address of the site as well as specify if the IP Address is Dedicated for that site or a Shared IP Address

I have figured out how to get the IP address of a site in PHP however I am not able to figure out how can I find out whether that IP address is static i.e. dedicated IP for the site or a shared IP that the site is using.

Does anyone know how to get around this problem, using PHP how can I figure out if an IP address of the site is a Dedicated IP address for that site or whether that IP is a shared one.

Any help on this matter is appreciated

Cheers
Asif
 

crisp

New Member
Messages
85
Reaction score
0
Points
0
What you're looking for is reverse DNS lookup (looking up domain names from ip address)

php uses gethostbyaddr() function for that

http://uk.php.net/gethostbyaddr

from that page, there's this post
Rathann
26-Feb-2006 05:51
While writing a script to verify IP<->hostname loops, I sorely missed the "list" version of gethostbyaddr (similar to gethostbynamel()) and since dns_get_record is a bit too complex for that task alone, I've written a simple wrapper that should behave like gethostbynamel():

function gethostbyaddrl($ip) {
$rrs=dns_get_record(implode('.',array_reverse(explode('.', $ip))).'.in-addr.arpa.',DNS_PTR);
$revnames=array();
foreach($rrs as $rr) $revnames[]=$rr['target'];
return (count($revnames)) ? $revnames : FALSE;
}

Hopefully it'll be of use to someone else, too.
which neatly uses dns_get_record function to pull the associated domains and put them in an array ($revnames) which I think is what you were after - ie, count($revnames > 1) = shared (although $revnames could be equal to one, still shared, but with only one domain currently attached)
 
Last edited:

phpasks

New Member
Messages
145
Reaction score
0
Points
0
What you're looking for is reverse DNS lookup (looking up domain names from ip address)

php uses gethostbyaddr() function for that

http://uk.php.net/gethostbyaddr

from that page, there's this post

which neatly uses dns_get_record function to pull the associated domains and put them in an array ($revnames) which I think is what you were after - ie, count($revnames > 1) = shared (although $revnames could be equal to one, still shared, but with only one domain currently attached)

Currently my problem solved.

I have got my doamin ip.

Currently my problem solved.

I am compare title for domain throw and ip throw.

I need how much sites in that shared ip. ?????

PHP:
<?php
//call function 

get_ip('yahoo.com');

function get_ip($val)
{
    $handle = fopen('http://www.'.$val, "r");
    stream_set_timeout($handle, 10);
    
    $contents = '';
    if($handle)
    {
        while (!feof($handle)) {
            $contents .= fread($handle, 8192);
        }
        $contents    =    strtolower($contents);
        fclose($handle);
    }
    preg_match('/<title>([^>]*)<\/title>/si', $contents, $match );

    $title_name    =    "";
    if (isset($match) && is_array($match) && count($match) > 0)
    {
        $title_name = strip_tags($match[1]);
    }
    
    $sdip = gethostbyname($val);
    $handle = fopen("http://".$sdip, "r");
    stream_set_timeout($handle, 10);
    
    $contents = '';
    if($handle)
    {
        while (!feof($handle)) {
            $contents .= fread($handle, 8192);
        }
        $contents    =    strtolower($contents);
        fclose($handle);
    }
    preg_match('/<title>([^>]*)<\/title>/si', $contents, $match );
    $title_ip = "";
    if (isset($match) && is_array($match) && count($match) > 0)
    {
        $title_ip = strip_tags($match[1]);
    }
    
    if($title_name==$title_ip)
        return " - <span style='color:#FF0000; font-weight:bold'>Dedicated IP</span>";
    else
        return " <span style='color:#0000FF; font-weight:bold'>Shared IP</span>";    
}
?>
 
Top