Security TypeError和python 3.5的问题 所以,我正在做一个IDS——我正在检测连接到主机的连接过程。当我最终运行它时,我得到了以下信息: Exception in thread Thread-3709: Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/threading.py", line 914, in _bootstrap_inner self.run() File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/threading.py", line 862, in run self._target(*self._args, **self._kwargs) TypeError: Scan() argument after * must be a sequence, not int

Security TypeError和python 3.5的问题 所以,我正在做一个IDS——我正在检测连接到主机的连接过程。当我最终运行它时,我得到了以下信息: Exception in thread Thread-3709: Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/threading.py", line 914, in _bootstrap_inner self.run() File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/threading.py", line 862, in run self._target(*self._args, **self._kwargs) TypeError: Scan() argument after * must be a sequence, not int,security,python,tcp,Security,Python,Tcp,代码如下: import threading import socket print("[*] Starting HazimIDS\n") def Scan(port): while True: noPrint = '' stcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sudp = socket.socket(socket.AF_INET, socket.SOCK_DG

代码如下:

import threading
import socket

print("[*] Starting HazimIDS\n")

def Scan(port):
    while True:
        noPrint = ''

        stcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sudp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

        stcp.bind(('127.0.0.1', port))
        sudp.bind(('127.0.0.1', port))

        Threads = StartListening(stcp, sudp)

        TCPThread = Threads[0]
        UDPThread = Threads[1]

        ConnectionThread = threading.Thread(target=DealWithConnections, args=(TCPThread, UDPThread))

        RawPackThread    = threading.Thread(target=PrintConnections, args=(listConnection))

        ConnectionThread.start()

        RawPackThread.start()

        while True:
            try:
                TCPTrue

                portstr = str(port)

                for x in range(len(recentports)):
                    port = recentports[x]

                    if portstr == port:
                        noPrint = 'true'
                    else:
                        continue

                if noPrint == '':
                    recentports.append(portstr + "-tcp")
                    print("[*] New Connection Found on port: " + portstr)
                else:
                    continue
            except NameError:
                continue




def ListenTCP(socketObj):
    while True:
        socketObj.listen(1)

        global TCPConnection
        TCPConnection = 'true'

def ListenUDP(socketObj):
    while True:
        data, addr = socketObj.recvfrom(4096)
        global UDPConnection
        UDPConnection = ['true', addr]

def StartListening(socketObjTCP, socketObjUDP):
    ttcp = threading.Thread(target=ListenTCP, args = (socketObjTCP))
    tudp = threading.Thread(target=ListenUDP, args = (socketObjUDP))

    return([ttcp, tudp])

def DealWithConnections(TCPThread, UDPThread):
    TCPThread.start()
    UDPThread.start()

    global listConnection

    listConnection = []

    while True:
        if TCPConnection == 'true':
            try:
                test = listConnection[1]
            except IndexError:
                listConnection.append('tcp')

        elif UDPConnection[0] == 'true':
            try:
                test = listConnection[1]
            except IndexError:
                listConnection.append('udp')

def PrintConnections(globalListConnection):
    while True:
        try:
            test = globalListConnection[1]

            fListVar = globalListConnection[0]

            if test == 'tcp':
                global TCPTrue
            elif test == 'udp':
                global UDPTrue
            elif fListVar == 'tcp':
                global TCPTrue
            elif fListVar == 'udp':
                global UDPTrue

        except IndexError:
            continue


def main():   
    for x in range(4000):
        ScanThread = threading.Thread(target=Scan, args=(x))
        ScanThread.start()

if __name__ == "__main__":
    main()

如果有人能帮助我并消除所有错误,我们将不胜感激。

您需要将
Thread()
args
参数值定义为一个序列;您不需要在这里:

RawPackThread    = threading.Thread(target=PrintConnections, args=(listConnection))
(listConnection)
不是元组,因为缺少逗号:

RawPackThread    = threading.Thread(target=PrintConnections, args=(listConnection,))
这同样适用于
StartListening
中的
Thread()
调用:

ttcp = threading.Thread(target=ListenTCP, args = (socketObjTCP))
tudp = threading.Thread(target=ListenUDP, args = (socketObjUDP))
应该是

ttcp = threading.Thread(target=ListenTCP, args = (socketObjTCP,))
tudp = threading.Thread(target=ListenUDP, args = (socketObjUDP,))
我不会使用列表在线程之间进行通信;请改为使用来自的线程安全对象