richardpenman / whois

MIT License
374 stars 188 forks source link

Add support for pure IP addresses and autonomous systems #163

Open PlasmaHH opened 1 year ago

PlasmaHH commented 1 year ago

Hi, while testing if I could use the library for some firewall log annotation system I stumbled over that the library can not quite properly do whois lookups for ip addresses. I would expect

whois.whois('8.8.8.8')

to behave the same as

whois 8.8.8.8

on the command line, however it does not. It will for some reason I can't quite understand do a query for the resolved hostname (dns.google.) instead. Additionally if I use whois.py directly I can see in the communication that it queries the correct server, but it seems that the whois exectuable does use n + 8.8.8.8\r\n instead, while this library doesn't send the n + part. For some other IPs the format of the query is even more different, I guess it depends on the RIR....

Additionally it would be nice to support lookup for autonomous systems as in whois AS15169

artv2007 commented 1 year ago

Hi, if I understood you correctly, you need a little fix in the function 'def whois' in the file init.py Comment or remove this strings try: result = socket.gethostbyaddr(url) except socket.herror as e: pass else: domain = extract_domain(result[0]) In this function code try to get hostname by ip address and then get whois of hostname, not of ip.

interplexed commented 6 months ago

The edit suggested by artv2007 seems to be on the right track. On Windows 11 I went to AppData\Local\Programs\Python\Python311\Lib\site-packages\whois and commented out those lines in the init.py file.
However, it seems to return all entries except the "emails" as null. Without this edit, it's working well, just has network latency I guess, with the additional DNS resolution?

Elektordi commented 1 month ago

I just tested with last pip version, no problem with IP address lookup! But still missing AS-number lookup.