My code is:
from ipwhois import IPWhois
import pprint
obj = IPWhois('74.125.227.206')
results = obj.lookup_rws()
pprint.pprint(results)
It returns:
{'asn': '15169',
'asn_cidr': '74.125.227.0/24',
'asn_country_code': 'US',
'asn_date': '2007-03-13',
'asn_registry': 'arin',
'nets': [{'abuse_emails': '[email protected]',
'address': '1600 Amphitheatre Parkway',
'cidr': '74.125.0.0/16',
'city': 'Mountain View',
'country': 'US',
'created': '2007-03-13T12:09:54-04:00',
'description': 'Google Inc.',
'handle': u'NET-74-125-0-0-1',
'misc_emails': None,
'name': 'GOOGLE',
'postal_code': '94043',
'range': u'74.125.0.0 - 74.125.255.255',
'state': 'CA',
'tech_emails': '[email protected]',
'updated': '2012-02-24T09:44:34-05:00'}],
'query': '74.125.227.206',
'raw': None}
What is the best or easiest way in python to print a single line from the output?
For example:
'name': 'GOOGLE',
or 'abuse_emails': '[email protected]',
Any help would be appreciated!!
results is already a dictionary, so just get the keys and values that you want.
from ipwhois import IPWhois
obj = IPWhois('74.125.227.206')
results = obj.lookup_rws()
print(results['nets'][0]['name'])
lookup_rws() function is deprecated. Instead, use:
from ipwhois import IPWhois
obj = IPWhois('{}'.format('IP') # Enter IP
result = obj.lookup_rdap(depth=1)
print(result['network']['name'])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With