My Port Scannerがポートをスキャンしています(想定しています)。しかし、アクティブポート(ポート80など)であっても、ポートが閉じていることを示しています。私は間違って何をしていますか?ポートスキャナがPythonでポートをスキャンしないのはなぜですか?
コード:
#!usr/bin/env python
import subprocess
import ipaddress
import socket
# Value to scan the network 192.168.2.0 till 192.68.2.14
net_addr = '192.168.2.0/28'
# Variables for the port numbers
portstart = 70
portend = 81
# Resolve hostname
host = socket.gethostname()
# Creates the network
ip_net = ipaddress.ip_network(net_addr)
# Get all hosts on the network
all_hosts = list(ip_net.hosts())
# Configure subprocess to hide the console window
info = subprocess.STARTUPINFO()
info.dwFlags |= subprocess.STARTF_USESHOWWINDOW
info.wShowWindow = subprocess.SW_HIDE
# Loop where the IP-address is being pinged.
for i in range(len(all_hosts)):
output = subprocess.Popen(['ping', '-n', '1', '-w', '500', str(all_hosts[i])], stdout=subprocess.PIPE,
startupinfo=info).communicate()[0]
if "Destination host unreachable" in output.decode('utf-8'):
print(str(all_hosts[i]), "is Offline")
elif "Request timed out" in output.decode('utf-8'):
print(str(all_hosts[i]), "is Offline")
else:
print(str(all_hosts[i]), "is ONLINE!")
print ("The hostname is:", host)
for portnum in range (portstart, portend):
try:
s.connect(all_hosts,portnum)
print("Port", portnum, "is OPEN!")
s.close()
except:
print("Port", portnum, "is closed")
結果:https://gyazo.com/da7d1eebfe4c3ffe4082fafd519eced2
私は私のファイアウォールとMalwarebytesををオフにし、それはまだ動作しません。
変数sを使用するために文字列に変換するために必要れるリスト機能を使用していたことを私はして直面していた問題は、あなたのスニペットで定義されていません? –