-1
我正在嘗試創建一個端口掃描器,用戶可以在其中鍵入要在主機上掃描的端口範圍,我將輸入從str轉換爲int範圍但它仍然表示這是一條大街。這裏是我的代碼:即使當我將str轉換爲int時,它仍然表示它是str
os.system('cls')
host = raw_input('Enter hostname or IP address: ')
target = socket.gethostbyname(host)
# converts hostname to IP address
portRange1 = raw_input("Please enter the first number (x) in your range (x, y): ")
portRange2 = raw_input("Please enter the second number (y) in your range (" + portRange1 + ", y): ")
# asks user for range of ports to scan
portRange1 = int(portRange1)
portRange2 = int(portRange2)
# converts variables from str to int
os.system('cls')
# clears console screen
print 'Starting scan on host ' + target
for port in range(portRange1 + ", " + portRange2):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = sock.connect_ex((target, port))
if result == 0:
print "Port {}: Open".format(port)
sock.close()
choice()
# scans for ports 0-1025 on host
choice()
而且我的錯誤是:
File "swisshack_W2.py", line 61, in portScanner
for port in range(portRange1, ", ", portRange2):
TypeError: range() integer end argument expected, got str.
' 「」'是不是一個整數。 – user2357112
'對於範圍內的端口(portRange1 +「,」+ portRange2):' '「,」是什麼與你混在一起我認爲 – Nullman
此外,您發佈的代碼與您發佈的錯誤消息不匹配。 – user2357112