Get ISP from IP Address using PHP **URGENT 500 POINTS**

I want to get a users ISP, City and State from their IP address. I don't really have $320 for GeoIP what else can I do and GeoLite City is very inaccurrate. Is there anyway I can use dig or something to do it.

Max
LVL 4
TheMaximumWeaselAsked:
Who is Participating?
 
missilesiloCommented:
Try an ARIN Whois.

<?php

$ip_address = $_SERVER["REMOTE_ADDR"];

$content = file_get_contents("http://ws.arin.net/cgi-bin/whois.pl?queryinput=$ip_address");

$pos = strpos($content, "<pre") + 4;
$content = substr($content,$pos);

$pos = strpos($content, "OrgName:") + 8;
$content = substr($content,$pos);
$pos = strpos($content, "\n");
$isp_name = trim(substr($content,0,$pos));
$content = substr($content,$pos);

$pos = strpos($content, "City:") + 5;
$content = substr($content,$pos);
$pos = strpos($content, "\n");
$city = trim(substr($content,0,$pos));
$content = substr($content,$pos);

$pos = strpos($content, "StateProv:") + 10;
$content = substr($content,$pos);
$pos = strpos($content, "\n");
$state = trim(substr($content,0,$pos));
$content = substr($content,$pos);

echo "ISP: $isp_name\n";
echo "City: $city\n";
echo "State: $state\n";

?>
0
 
ixtiCommented:
If you are using PHP 5.x then you can use PEAR package Net_GeoIP (http://pear.php.net/package/Net_GeoIP)
0
 
Joseph MelnickSenior Software Developer - Pharmacy ApplicationsCommented:
Hello TheMaximumWeasel,

A good place to aquire ip to location data is www.hostip.info. These people provide this data at no cost. Read and follow their terms and agreements and us their data. Very Cool.

It provides data for IP address lookup to City, State, Country.

Joseph Melnick (jmelnick)
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
Joseph MelnickSenior Software Developer - Pharmacy ApplicationsCommented:
This approach is ok for low volume lookups but I expect that are limit. Joseph
0
 
TheMaximumWeaselAuthor Commented:
I like the idea of the net_geoIP but does that give more than the country and is it accurate. cause just mod_geoip is just the country and if I get the geoLite city from maxmind (opensource geoip) it isn't accurate at all.

Max
0
 
ixtiCommented:
I didn't used this packege before, so I can't say more info about it.
You can get info about what Net_GeoIP packege can do here:

http://pear.php.net/package/Net_GeoIP/docs/latest/Net_GeoIP/Net_GeoIP.html

As I understand, this package can use free and commercial DataBase.
0
 
Joseph MelnickSenior Software Developer - Pharmacy ApplicationsCommented:
Hello TheMaximumWeasel,

net_geoip uses maxmind free or commercial databases so your free option is country only data.

Did you look into hostip.info?

Joseph Melnick
0
 
missilesiloCommented:
The code I posted retrieves the ISP, City and State from an IP address.

Have you tried it?
0
 
missilesiloCommented:
Thanks for the A
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.