我试图在用户指定的端口范围内一次扫描一个IP地址,直到第四个八位字节达到255。但是,我遇到了一个错误,没有定义名为“count”的变量,尽管我将其定义为=1,因此程序会在每个IP地址(如53.234.12.1、53.234.12.2、53.234.12.3等)中运行
这就是我试图在口译员中展示的东西,毕竟我说了这么多,做了这么多: End Result
这是我的密码:
import socket
server = 'google.com'
startPort = int(input("Enter started port number to scan: "))
endPort = int(input("Enter ending port number to scan: "))
threeOctet = str(input("Enter the first three octets of an IP to scan: "))
countFullIP = threeOctet + "." + str(count)
count = 1
for countFullIP in range(0,256):
for count in range (startPort,endPort):
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((server,countFullIP))
print('IP',countFullIP)
except:
print('IP is invalid')
try:
print('Port',count,'is open')
except:
print('Port',count,'is closed')
任何协助都将不胜感激。谢谢你
更换两条管路
至
如您所见,count在赋值之前被引用
根据评论中提到的附加要求更新规范
相关问题 更多 >
编程相关推荐