tags:

views:

1070

answers:

5

I'm trying to programmaticaly determine the company* associated with a given IP address.

My first guess was this :

  string hostname = Dns.GetHostEntry(IPAddress.Parse(ip)).HostName;

but this won't work if the reverse DNS isn't set correctly, which seems to happen 90% of the time.

However some websites are still able to successfully determine the company associated with a specific IP even if the reverse dns fails. For example, on this site, the ISP Provider field sometimes contains valuable information (ie the name of the company) even if the hostname isn't set.

What's the easiest way to achieve the same thing using .net ?


Notes :

  • I don't need a canonical name. ie MS or Microsoft are both ok.
  • I'm targeting big companies, which are likely to "own" their IP address ranges.
  • I'm running on Windows, so unix's whois tools are not installed by default.


Edit regarding the use of whois : Sometimes, there's no whois information associated with an IP

A: 

You can do a whois lookup on the https://ws.arin.net/whois website and parse out the information you are looking for.

heavyd
Unfortunately, it doesn't provide the information I'm looking for
Brann
That's how this kind of info is likely being determined, however, by figuring out who owns the blocks of IPs (which comes from the ARIN database). There may be successive whois queries.
Joe
+2  A: 

You can install the whois command line tool for windows from microsoft

edit: then what information are you looking for ?

>whois bbc.co.uk
Domain name:
    bbc.co.uk

Registrant:
    British Broadcasting Corporation

Registrant type:
    UK Limited Company, (Company number: 000057)

Registrant's address:
    Research & Development
    Kingswood Warren
    Tadworth
    Surrey
    KT20 6NP
    United Kingdom

Registrar:
    British Broadcasting Corporation [Tag = BBC]
Martin Beckett
Unfortunately, it doesn't provide the information I'm looking for.
Brann
Can you provide details, such as an example IP address? Besides DNS and whois, there is NOT an *automatic* way to get any information from an IP address.
bortzmeyer
A: 

Mostly I'm seconding the "whois" answers. Back in the day companies owned whole blocks of addresses, so it used to be fairly easy for people to write their own "whois", but as IP(v4) addresses got more scarce, it quit being easy. I wouldn't even think of trying it now. Use a real whois.

T.E.D.
A: 

Check this http://ws.arin.net/whois/ it should provide the info you require

You could try requesting

http://ws.arin.net/whois/?queryinput={ipaddress} using a WebClient or WebRequest and then try parsing the returned string.

A simple string.IndexOf("OrgName:") lookup should get you close.

example url http://ws.arin.net/whois/?queryinput=207.46.193.254

HTH

OneSHOT

OneSHOT
A: 

As with many programatic concerns, what you are asking is not as simple as you might expect.

Question(s) first... what is the source of the IP address you wish to resolve - a website "visitor", a web server or an unknown source? For the purpose of this response, I'll make the presumption that you are wish to "convert" a website visitor as this is the most common/valuable reason to resolve IP->Company.

Issue One... Using WHOIS you can resolve the "owner" of the netblock (IP Address range) associated with an IP address in question. The "owner" of the netblock is (usually) the ISP serving the company you're wishing to identify - not the company utilizing the IP address.

Issue Two... DNS is not a reliable source for anything beyond IP->domain.tld or domain.tld->ip type resolution. Beyond that it's not enforced (not really) and not completely reliable.

Issue Three... This may not be an issue for you. Depending on the NIC (ARIN, RIPE, et.al.) who resolved your WHOIS query, you'll find that the resultant format is not always easy to parse - readable... yes, parsable... no.

Jeffrey M