tags:

views:

31

answers:

1

I need to make it with PHP, maybe with some pear package or php internal functions. How i can do that ?

I know i need gethostbyname() for hostname checking, but i need also ip range of this provider. example: ip: 5.7.8.9 host: usa provider ip range 5.7.8.0-5.7.9.0

Is it possible with php?

+2  A: 

There's no way to accurately see IP ranges without access to BGP, but if you trust the ISPs to provide the correct information you can get it from whois. Use shell_exec or similar to call the command-line whois client.

I propose you heck for these labels:

  • inetnum
  • NetRange
  • CIDR
  • route

And possibly more. Whois is however not always trustworthy. It's a text database with no defined standard format, so you may not always get a usable answer, and you don't always know what to look for.

As I said, the most trustworthy solution is to get real BGP access so you can check actual Internet routing. This is however rather advanced, so maybe there is some web service you can use for routing lookups?

Edit I actually found this project, which provides an API for BGP queries: http://www.routeviews.org/

There are two sub-domains of TXT reconds in routeviews.org, asn and aspath. asn.routeviews.org maps (resolves) a reversed IPv4 address or prefix (eg: 128.223 -> 223.128.asn.routeviews.org) to the origin AS (and prefix and prefix length) of the best route as seen by route-views2.routeviews.org. aspath.routeviews.org is the same idea, but resolves to the full AS path.

This can possibly be used for getting the subnet of an IP through simple DNS queries. Whit the subnet it's easy to calculate the IP range (as you probably already know, the range is just a different notation of the subnet).

Emil Vikström