Skip to content

Instantly share code, notes, and snippets.

@avamsi
Created September 5, 2016 11:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avamsi/d8f0ecb2b28cad6c3f74a7d2205d395d to your computer and use it in GitHub Desktop.
Save avamsi/d8f0ecb2b28cad6c3f74a7d2205d395d to your computer and use it in GitHub Desktop.
import collections
import socket
import threading
def worker(ipaddr):
try:
hostname = socket.gethostbyaddr(ipaddr)[0]
except socket.herror:
hostname = '--'
hosts[hostname].append(ipaddr)
def wait(threads):
for t in threads:
t.join()
def main():
threads = []
for i in range(98, 105):
for j in range(256):
ipaddr = '172.16.%s.%s' % (i, j)
t = threading.Thread(target=worker, args=(ipaddr,))
threads.append(t)
t.start()
wait(threads)
if __name__ == '__main__':
hosts = collections.defaultdict(list)
main()
hosts_w_mi = [
(len(ipaddrs), hostname) for hostname, ipaddrs in hosts.items()
if len(ipaddrs) != 1]
print(*sorted(hosts_w_mi), sep='\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment