Reputation: 560
I have installed Scapy from the package repos on my Ubuntu machine (Python 2.7), and I am trying to run this code from a file:
import scapy
dg = scapy.IP()
pcap = scapy.rdpcap("../tst/Http.cap")
scapy.send(IP())
Running gives the error,
AttributeError: 'module' object has no attribute 'IP'
Comment out the IP call on line 3 and running gives the error,
AttributeError: 'module' object has no attribute 'rdpcap'
Also comment out line 4 and you get,
AttributeError: 'module' object has no attribute 'send'
Curously, this code fails when invoked with ''python '', but it works as expected when I manually enter each command into the Python shell. I have observed this behaviour on three fresh Python installs - two in Ubuntu, and one in Windows. Can anyone else see the cause of this error?
Upvotes: 2
Views: 12877
Reputation: 8147
You need to import Scapy into the global namespace.
From the Scapy module documentation -
Note: In Scapy v2 use from scapy.all import * instead of from scapy import *.
Also found in "Using Scapy to build your own tools".
So your code should be -
from scapy.all import *
dg = IP()
pcap = rdpcap("../tst/Http.cap")
send(IP())
Upvotes: 6