TypeError:str,bytes或bytearray expected,而不是int

时间:2017-10-02 23:54:47

标签: python multithreading python-3.x

我知道其他有相同错误的问题已经得到解答,但我尝试了解决方案而且他们根本不工作。我有一个简单的端口扫描程序,但我收到此错误:

 File "C:\Program Files (x86)\Python\Python36-32\lib\threading.py", line 916, in _bootstrap_inner
    self.run()
  File "C:\Program Files (x86)\Python\Python36-32\lib\threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "C:/Users/Dark/IdeaProjects/port/scanner.py", line 16, in scan
    result = s.connect_ex((host,port))
TypeError: str, bytes or bytearray expected, not int

我到目前为止的代码是:

from threading import Thread
import socket
host = int(eval(input('host > ')))
from_port = int(eval(input('start scan from port > ')))
to_port = int(eval(input('finish scan to port > ')))
counting_open = []
counting_close = []
threads = []

def scan(port):
    s = socket.socket()
    result = s.connect_ex((host,port))
    print(('working on port > '+(str(port))))
    if result == 0:
        counting_open.append(port)
        #print((str(port))+' -> open')
        s.close()
    else:
        counting_close.append(port)
        #print((str(port))+' -> close')
        s.close()

for i in range(from_port, to_port+1):
    t = Thread(target=scan, args=(i,))
    threads.append(t)
    t.start()

[x.join() for x in threads]

print(counting_open)

错误在这种情况下意味着什么,我该如何解决?请不要将我的其他问题转介给我,我已经阅读过了!

0 个答案:

没有答案