Discussion:
import scapy.all
pentester
2012-09-23 13:22:49 UTC
Permalink
If I launch a python script from the command line, there is an error message.
But launching python from the command line and add the script as an argument, works fine.

I have included a simple example as proof of concept. It just prints de __doc__ of scapy's sr function.

This is the script:
$ cat tmp.py
#! /usr/bin/python
from scapy.all import *
print ("This is sr.__doc__\n%s") % (sr.__doc__)

This is the output:
$ python tmp.py
This is sr.__doc__
Send and receive packets at layer 3
nofilter: put 1 to avoid use of bpf filters
retry: if positive, how many times to resend unanswered packets
if negative, how many times to retry when no more packets are answered
timeout: how much time to wait after the last packet has been sent
verbose: set verbosity level
multi: whether to accept multiple answers for the same stimulus
filter: provide a BPF filter
iface: listen answers only on the given interface

Everything works as expected. It is clear the scapy.all module can be found.

But when I launch the script without invoking python first, it fails:
$ ./tmp.py
Traceback (most recent call last):
File "./tmp.py", line 2, in <module>
from scapy.all import *
ImportError: No module named scapy.all

I googled but answers to similar questions didn't solve the issue so far. Does anyone has a clue what is happening here?

For what it's worth:
- It fails on Mac (Darwin Kernel Version 10.8.0), but works on linux (Backtrack distro)
- scapy is installed using macport
$ port installed | grep -i scapy
py26-scapy @2.1.0_0 (active)

cr
Tobias Mueller
2012-09-23 13:26:26 UTC
Permalink
Heya,
Post by pentester
$ cat tmp.py
#! /usr/bin/python
from scapy.all import *
print ("This is sr.__doc__\n%s") % (sr.__doc__)
[...]
$ ./tmp.py
So you have "/usr/bin/python" as your shebang. What does "which python"
tell you? And does "/usr/bin/python tmp.py" work?

Cheers,
Tobi

---------------------------------------------------------------------
To unsubscribe, send a mail to scapy.ml-***@secdev.org
pentester
2012-09-23 13:34:06 UTC
Permalink
Tobias,

You just solved the issue.

$ which python
/opt/local/bin/python

I changed the shebang and it works now. I'm glad no one is home and see me blushing, because this is something I should have found myself.
But I didn't and you did. You're my her for today.

Cor
Post by Tobias Mueller
Heya,
Post by pentester
$ cat tmp.py
#! /usr/bin/python
from scapy.all import *
print ("This is sr.__doc__\n%s") % (sr.__doc__)
[...]
$ ./tmp.py
So you have "/usr/bin/python" as your shebang. What does "which python"
tell you? And does "/usr/bin/python tmp.py" work?
Cheers,
Tobi
---------------------------------------------------------------------
To unsubscribe, send a mail to scapy.ml-***@secdev.org
pentester
2012-09-23 13:39:44 UTC
Permalink
Oops, a nasty typo. I meant to write: You're my hero for today.
And what the last sentence says makes me even more blushing. Perhaps I better stay away from this keyboard for the rest of the day :-)

Cor
Post by pentester
Tobias,
You just solved the issue.
$ which python
/opt/local/bin/python
I changed the shebang and it works now. I'm glad no one is home and see me blushing, because this is something I should have found myself.
But I didn't and you did. You're my her for today.
Cor
Post by Tobias Mueller
Heya,
Post by pentester
$ cat tmp.py
#! /usr/bin/python
from scapy.all import *
print ("This is sr.__doc__\n%s") % (sr.__doc__)
[...]
$ ./tmp.py
So you have "/usr/bin/python" as your shebang. What does "which python"
tell you? And does "/usr/bin/python tmp.py" work?
Cheers,
Tobi
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, send a mail to scapy.ml-***@secdev.org
Tobias Mueller
2012-09-23 13:53:33 UTC
Permalink
Heya,
Post by pentester
$ which python
/opt/local/bin/python
I'd use /usr/bin/env python as shebang and not a hard coded path to a
python interpreter.

But well, I would as well not use a Mac to begin with ;-)

Cheers,
Tobi

---------------------------------------------------------------------
To unsubscribe, send a mail to scapy.ml-***@secdev.org
Dirk Loss
2012-09-23 14:43:00 UTC
Permalink
Post by pentester
If I launch a python script from the command line, there is an error message.
But launching python from the command line and add the script as an argument, works fine.
$ cat tmp.py
#! /usr/bin/python
from scapy.all import *
Your shebang line "#! /usr/bin/python" apparently does not start the
Python interpreter that you have installed Scapy for.

Type "which python" and correct that line accordingly.
For example:
#! /usr/local/bin/python

Best regards
Dirk

---------------------------------------------------------------------
To unsubscribe, send a mail to scapy.ml-***@secdev.org

Loading...