1

I am having an issue with scapy importing into a python script. I am using python 2.7. Scapy runs fine through interactive view but trying to write a custom script fails, name 'IP' is not defined

import sys
from scapy.all import *

p=sr(IP(dst="10.1.99.2")/TCP(dport=80))

print 'success'

On my end, using ubuntu 14.04 with latest scapy installed and python 2.7 running that script shoots off fails for importing several different layers with errors such as "can't import layer inet: name 'IP' is not defined"

any idea's?

Edit : Solved : dunno what it was, but the py file being on my desktop prevented it from running properly. Once I moved it to a downloads folder, it worked fine

In the stars
  • 253
  • 4
  • 17
  • How did you install scapy? pip? or apt-get? – Noam Rathaus Mar 22 '15 at 02:21
  • sudo apt-get install scapy -- which occurred directly after installing ubuntu 14.04 on a vm – In the stars Mar 22 '15 at 02:36
  • strange, try to use "apt-get remove scapy && pip install scapy" maybe the apt-get version is broken? I use the pip one as it is newer version – Noam Rathaus Mar 22 '15 at 02:38
  • Upon typing the command above I was told I didn't have pip installed and instructed to install python-pip - after installing python-pip and rerunning above script, it states 'requirements already satisfied' When trying to run my own scapy script, it still gives the many "can't import layer XXX: name 'IP' is not defined" with the XXX being many scapy modules? and at the end says TypeError: 'str' object is not callable – In the stars Mar 22 '15 at 03:04
  • Do you have it installed through dpkg? do `dpkg -l | grep scapy` does it return? if so, try to uninstall it `apt-get remove...` and then through pip install it – Noam Rathaus Mar 22 '15 at 03:06
  • also try: `from scapy.all import *` followed by `dir(IP)`, the latter should return something – Noam Rathaus Mar 22 '15 at 03:07
  • the dkpg command resulted in python-scapy -- so I apt-get removed python-scapy then reran sudo pip install scapy this installed scapy successfully reran my script and exact same problem If I ran it with dir(IP) I get : NameError : name 'IP' is not defined – In the stars Mar 22 '15 at 03:11
  • Hi, what is the same of your file btw... :) is it scapy? or IP? ... – Noam Rathaus Mar 22 '15 at 04:30
  • possible duplicate of http://stackoverflow.com/questions/13610064/scapy-all-import-does-not-work – Noam Rathaus Mar 22 '15 at 04:30
  • I am not executing it from within the folder that has scapy.py in it, nor is my file called scapy.py -- just called new2.py and on desktop not user/bin or etc – In the stars Mar 22 '15 at 04:37
  • sorry, that is my 2cnt, no other idea – Noam Rathaus Mar 22 '15 at 05:43

1 Answers1

0

From what I assume at this point, the file being on my desktop is what was triggering the issue - might be user restrictions inherent on ubuntu - however, after moving the .py file outside of my desktop folder, to downloads folder - it worked no more errors

In the stars
  • 253
  • 4
  • 17