for host in hosts:
with open(f'current_{host}', 'r') as ex_ports:
ex_ports = ex_ports.readlines()
for line in ex_ports:
ports.append(line.strip('\n').strip())
with open(f'current_{host}', 'w') as c_host:
print (f'{host} : {ports}')
for port in range(1, 65535):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(1)
result = sock.connect_ex((host, port))
if result == 0:
if port not in ports:
message = f"Host: {host}, Port: {port} is open."
# send_telegram_message(telegram_token, chat_id, message)
print (port)
c_host.write (f'{port}\n')
为什么支票不起作用if not in
?我之前用过类似的方法,一切正常。这段代码列出了所有开放的端口,不关注这个比较。