i m trying to capture ethernet packet using pycap http://pycap.sourceforge.net/. when i use following command on python prompt with root privileges, it is working
>>>import pycap.capture
>>>p = pycap.capture.capture("wlan0")
>>>p.next()
(Ethernet(type=0x608, 00:1b:b1:46:53:5d -> ff:ff:ff:ff:ff:ff), ARP(op=0x1, protocol=0x800, 00:1b:b1:46:53:5d (192.16.68.10) -> 00:00:00:00:00:00 (192.16.110.39)), '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', 1307898356.222398)
But if i run these commands as a script, i m getting following error
>>>sudo python pycap.py
Traceback (most recent call last):
File "pycap.py", line 2, in <module>
from pycap import *
File "/home/nikhil/Code/Python/pycap.py", line 5, in <module>
p = capture.capture(device)
NameError: name 'capture' is not defined
Any suggestions?
pycap http://pycap.sourceforge.net/ says it is requires python2.3 and im using python2.6. Is that a problem?
Your script using
pycapis calledpycapitself, soimport pycapimports itself (.is usually the first directory on the import path). Because imports are caches, this doesn’t lead to infinite recursion but instead gives you a reference to your own module, which of course doesn’t definecaptureor anything else. Rename it.