Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- file_name = 'hosts.txt'
- def read_hosts(file):
- hosts = []
- with open(file, 'r') as f:
- for host in f.readlines():
- hosts.append(host.strip())
- return hosts
- def check_host():
- filtered = {}
- opened = {}
- for host in read_hosts(file_name):
- try:
- ip = socket.gethostbyname(host)
- if ip.startswith('10.10.'):
- filtered[host] = ip
- else:
- opened[host] = ip
- except socket.gaierror:
- pass
- show_result(filtered, opened)
- def show_result(filtered, opened):
- print('[X] Filtered hosts:')
- for host, ip in filtered.items():
- print('\t[X] {} - {}'.format(host, ip))
- print('[+] Open hosts:')
- for host, ip in opened.items():
- print('\t[+] {} - {}'.format(host, ip))
- if __name__ == '__main__':
- check_host()
Add Comment
Please, Sign In to add comment