PHP lookup ISP of an IP (without paying)

Associate
Joined
8 May 2009
Posts
296
Hi,

I've made a simple facility which reads a big list of IPs, and outputs where they're based.

I used GeoIP to do this.

I'd now like to get the ISP that the IP's belong to but I'm struggling to find a way other than one or two paid services. As this is simply a home project I'd rather not pay.

Does anyone know of any solutions to this? (Or is anyone willing to pay for the service for me? :D )

Thanks,
Redrabbit
 
Wise Guy
Soldato
Joined
23 May 2009
Posts
5,748
Code:
$ip = "185.103.4.0";

exec('whois '. $ip, $output);

foreach ($output as $record) {
    if (strpos($record, 'org-name') !== false) {
        $owner =  trim(substr($record, strpos($record, ":") + 1));
        echo $owner ."\n";
    }
}
 
Associate
OP
Joined
8 May 2009
Posts
296
Code:
$ip = "185.103.4.0";

exec('whois '. $ip, $output);

foreach ($output as $record) {
    if (strpos($record, 'org-name') !== false) {
        $owner =  trim(substr($record, strpos($record, ":") + 1));
        echo $owner ."\n";
    }
}

Hey thanks for that.

This unfortunately only works on a very limited set of IPs.

I'm now looking at paid solutions. I'd be willing to pay up to about 20 USD or GBP or similar for access to the records.
 
Wise Guy
Soldato
Joined
23 May 2009
Posts
5,748
Change it to this. It might not get some asian or south american ones, you'll have to look at the 'whois <ip addy>' output from the command line and see what to parse.

Code:
$ip = "1.2.3.4";

exec('whois '. $ip, $output);

foreach ($output as $record) {
   if (strpos($record, 'org-name') !== false || strpos($record, 'OrgName') !== false) {
        $owner =  trim(substr($record, strpos($record, ":") + 1));
        echo $owner;
    }
}

or just do this if it's under 1000 IPs

Code:
$ip = "1.2.3.4";
$org = file_get_contents("http://ipinfo.io/". $ip ."/org");
echo $org;
 
Back
Top Bottom