Monthly Archives: March 2012

Get host by IP address

Code to scan a certain range of IP addresses and display the corresponding hostnames:

import socket
socket.setdefaulttimeout(1)
for octet1 in range(64,64):
	for octet2 in range(233,233):
		for octet3 in range(160,191):
			for octet4 in range(0,255):
				ip = str(octet1)+"."+str(octet2)+"."+str(octet3)+"."+str(octet4)
				print(ip)
				try:
				    print (socket.gethostbyaddr(ip))
				except socket.herror, e:
				    print e
				
Advertisements