Created
September 5, 2016 11:13
-
-
Save avamsi/d8f0ecb2b28cad6c3f74a7d2205d395d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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