Reputation: 73
I try to run a python code from online course to create a raw network packet and send to a network by scapy with python 3.4.2 on Debian 9 but I got the error message as show below:
NameError: name 'IP' is not defined
when I look into the code:
#!/usr/bin/python
#for python 3 , must install scapy for python3 first by type command "pip3 install scapy-python3"
import scapy.all
frame = scapy.all.Ether(dst="15:16:89:fa:dd:09") / IP(dst="9.16.5.4") / TCP() / "This is my payload"
there is a red line under "IP" and "TCP" method and then It tell that those 2 methods are Unresolved reference
I try to change how to import scapy library
from
import scapy.all
to
from scapy.all import *
but the problem is not resolved. What do I something wrong?
Upvotes: 1
Views: 15804
Reputation: 436
Since you did
import scapy.all
You will have to refer all the types with the 'scapy.all' prefix.
>>> import scapy.all
>>> frame = scapy.all.Ether(dst="15:16:89:fa:dd:09") / IP(dst="9.16.5.4") / TCP() / "This is my payload"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'IP' is not defined
>>> frame = scapy.all.Ether(dst="15:16:89:fa:dd:09") / scapy.all.IP(dst="9.16.5.4") / scapy.all.TCP() / "This is my payload"
>>>
Another way around it is
from scapy.all import *
But that tends top pollute your namespace.
Upvotes: 0
Reputation: 2881
#!/usr/bin/python
#for python 3 , must install scapy for python3 first by type command "pip3 install scapy"
import scapy.all.Ether
import scapy.all.IP
import scapy.all.TCP
frame = Ether(dst="15:16:89:fa:dd:09") / IP(dst="9.16.5.4") / TCP() / "This is my payload"
Upvotes: 0
Reputation: 87
Okay , this may help you because I did the same mistake. Make sure your filename is not scapy.py
Upvotes: 0