# ports = [21, 22, 80, 135, 443, 445, 1433, 1521, 3306, 3389, 7001, 8000] ports = [22, 22, 80] server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) withopen('ip.txt', 'r') as f: for ip in f.readlines(): for port in ports: ip = ip.rstrip() # 去掉换行符 result = server.connect_ex((ip, port)) if result == 0: withopen("端口开放.txt", "a+") as w: w.write(f'{ip}:{port}'+'\n') print(f'{ip}:{port}端口是开放的') else: withopen("端口未开放.txt", "a+") as w: w.write(f'{ip}:{port}' + '\n') print(f'{ip}:的{port}的端口是关闭的') # print(result)
for host in nm.all_hosts(): print('主机 : %s ' % host) print('状态 : %s' % nm[host].state()) # up 表示在线,down表示不在线 for proto in nm[host].all_protocols(): # nm[host].all_protocols() 主机存活的所有协议 print('协议 : %s' % proto) lport = nm[host][proto].keys() for port in lport: print('端口号 : %s\t状态 : %s' % (port, nm[host][proto][port]['state']))
withopen('ip.txt', 'r') as f: withopen("result.txt", "a+") as w: for ip in f.readlines(): ip = ip.rstrip() nm = nmap.PortScanner() nm.scan(hosts=ip, arguments='-p 22-443 -sV')
for host in nm.all_hosts(): w.write(f'主机 : {host}\n') w.write(f'状态 : {nm[host].state()}\n') print('主机 : %s ' % host) print('状态 : %s' % nm[host].state()) # up 表示在线,down表示不在线 for proto in nm[host].all_protocols(): print('协议 : %s' % proto) w.write(f'协议 : {proto}\n') lport = nm[host][proto].keys() for port in lport: state_result = nm[host][proto][port]['state'] w.write(f'端口号 : {port}\t状态 : {state_result}\n') print('端口号 : %s\t状态 : %s' % (port, state_result))
评论区
欢迎你留下宝贵的意见,昵称输入QQ号会显示QQ头像哦~