Skip to content

Instantly share code, notes, and snippets.

@narbehaj
Created May 15, 2018 09:34
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 narbehaj/bd77600d79fa09f8c3a8da88c1446af4 to your computer and use it in GitHub Desktop.
Save narbehaj/bd77600d79fa09f8c3a8da88c1446af4 to your computer and use it in GitHub Desktop.
Checks host.txt file per line to see if the host is filtered in Iran or not.
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment