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
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]
You can do a whois lookup on the https://ws.arin.net/whois website and parse out the information you are looking for.
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.
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
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.
来源:https://stackoverflow.com/questions/1032457/how-can-i-determine-which-company-an-ip-address-belongs-to