pentester | 23 Sep 15:22 2012
Picon

import scapy.all

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 <at> 2.1.0_0 (active)

cr
Tobias Mueller | 23 Sep 15:26 2012
Picon

Re: import scapy.all

Heya,

On 23.09.2012 15:22, pentester wrote:
> This is the script:
> 
>     $ cat tmp.py
>     #! /usr/bin/python
>     from scapy.all import *
>     print ("This is sr.__doc__\n%s") % (sr.__doc__)
>  [...]
> But when I launch the script without invoking python first, it fails:
> 
>     $ ./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-unsubscribe <at> secdev.org

pentester | 23 Sep 15:34 2012
Picon

Re: import scapy.all

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

On Sep 23, 2012, at 3:26 PM, Tobias Mueller wrote:

> Heya,
> 
> On 23.09.2012 15:22, pentester wrote:
>> This is the script:
>> 
>>    $ cat tmp.py
>>    #! /usr/bin/python
>>    from scapy.all import *
>>    print ("This is sr.__doc__\n%s") % (sr.__doc__)
>> [...]
>> But when I launch the script without invoking python first, it fails:
>> 
>>    $ ./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-unsubscribe <at> secdev.org

pentester | 23 Sep 15:39 2012
Picon

Re: import scapy.all

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

On Sep 23, 2012, at 3:34 PM, pentester wrote:

> 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
> 
> 
> On Sep 23, 2012, at 3:26 PM, Tobias Mueller wrote:
> 
>> Heya,
>> 
>> On 23.09.2012 15:22, pentester wrote:
>>> This is the script:
>>> 
>>>   $ cat tmp.py
>>>   #! /usr/bin/python
>>>   from scapy.all import *
>>>   print ("This is sr.__doc__\n%s") % (sr.__doc__)
>>> [...]
>>> But when I launch the script without invoking python first, it fails:
>>> 
>>>   $ ./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-unsubscribe <at> secdev.org
> 

---------------------------------------------------------------------
To unsubscribe, send a mail to scapy.ml-unsubscribe <at> secdev.org

Tobias Mueller | 23 Sep 15:53 2012
Picon

Re: import scapy.all

Heya,

On 23.09.2012 15:34, pentester wrote:
> $ 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-unsubscribe <at> secdev.org

Dirk Loss | 23 Sep 16:43 2012
Picon

Re: import scapy.all

On 23.09.12 15:22, pentester wrote:
> 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-unsubscribe <at> secdev.org


Gmane