0

I'm trying to get informations about some hostnames, for example the country of the registrant. I've found IPWhois who should do the job, but apparently it doesn't give me the expected data.

For example, I would like to know to which country is related Nokia (answer : Finland). I know that their hostname is nokia.com. So I've tried this:

import socket
from ipwhois import IPWhois
from pprint import pprint
ip = socket.gethostbyname('nokia.com')
obj = IPWhois(ip)
pprint(obj.lookup_rdap(depth=1))

Sadly the resutls don't show any information about Nokia, but about the hosting, which is in the U.S.

Using the Whois in Ubuntu Network Tools, I can see :

[…]
Registrant Name: Nokia Corporation
Registrant Organization: Nokia Corporation
Registrant Street: P.O. Box 226, Nokia Group
Registrant City: Espoo
Registrant State/Province: Espoo
Registrant Postal Code: 00045
Registrant Country: FI
[…]

Is there a way to get this kind of data?

[Edit] The script should work on Ubuntu server (from 12.04). As suggested, I can use the subprocess library to call check_output, as for example:

from subprocess import check_output
output = check_output(['whois', 'nokia.com'])

Then I need to process the output, as it can be different from a registrar to another.

  • 1
    First, it would be nice to tell us what os are you running this on –  Dec 02 '16 at 16:44
  • Depending on the OS you're using, Python may be able to run an OS provided tool and capture the information is provides for using in your script. – martineau Dec 02 '16 at 17:22
  • Your question is not clear. If from some company name like Nokia you want to get data then this is nothing related to Internet, you will need to search in databases on company registrations in various countries. If from some domain name (`nokia.com`) you want data, use domain name registry whois and look at registrant. If from some hostnames and hence IP you want to see where is it hosted (which can be completely elsewhere from the company offices), use whois on RIR servers; you can sometimes query there by name too to get back IP blocks registered by organization. – Patrick Mevzek Jan 02 '18 at 19:00

1 Answers1

0

IPWhois is for looking own ownership of IP addresses. Whois is for looking up ownership of domains.

Try using python-whois, like so:

In [15]: import whois

In [16]: w = whois.whois('nokia.com')

In [17]: for key in ('name', 'org', 'address', 'city', 'country'): print w[key]
Nokia Corporation
Nokia Corporation
P.O. Box 226, Nokia Group
Espoo
FI

In [18]: 
Robᵩ
  • 163,533
  • 20
  • 239
  • 308