Get whois information

We can use the Requests module and the whois.domaintools.com service to get information about the domain we are analyzing, such as the IP address and location.

You can find the following code in the get_whois_info.py file: 

#!/usr/bin/env python3
from lxml.html import fromstring
import requests
domain = input("Enter the domain : ")
url = 'http://whois.domaintools.com/' + domain
headers = {'User-Agent': 'wswp'}
resp = requests.get(url, headers=headers)
html = resp.text
tree = fromstring(html)
info = tree.xpath('//*[@id="stats"]//table/tbody/tr//text()')
temp_list = []

for each in info:
each = each.strip()
if each == "":
continue
temp_list.append(each.strip(" "))

ip_index = temp_list.index('IP Address')
print("IP address ", temp_list[ip_index + 1])
location = temp_list.index('IP Location')
location2 = temp_list.index('ASN')
print('Location : ', "".join(temp_list[location + 1:location2]))

In the output of the previous script, we can see information about the IP address and the location from the packtpub.com domain:

Enter the domain : http://www.packtpub.com
IP address 83.166.169.231 - 1 other site is hosted on this server
Location : -England-Derby-Node4 Uk Hosting
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset