Having an issue writing a python script with vim
#1
Hi hope someone on here can help me, I’m trying to write a python script using vim as the IDE then after saving changes and exiting running the code in the terminal:

#!/usr/bin/python
import sys
# then we import scapy:
from scapy.all import *
def PacketHandler(pkt):
print pkt.summary()
return
sniff(iface=sys.argv[1],count= int(sys.argv[2], prn= PacketHandler)

But, I’m getting a syntax _error_:

File "./packethandler.py", line 10
sniff=(iface =sys.argv[0], count =int(sys.argv[1]), prn =PacketHandler)
SyntaxError: invalid syntax

I can’t see anything wrong with the code, Does anyone maybe see something I’m missing ?
Reply
#2
Are you sure you're executing the same script that you posted?
There's an = after sniff in the error message, but seems to be 'omitted' from the script example.

Use [code] blocks while you're at it too for better formatting.
Reply
#3
(01-03-2021, 08:10 AM)poppopret Wrote: Are you sure you're executing the same script that you posted?
There's an = after sniff in the error message, but seems to be 'omitted' from the script example.

Thanks for your reply, I've run the script again and made sure there's
no = after sniff, However this time I'm getting a different error

#! /usr/bin/python
import sys
from scapy.all import *

def PacketHandler(pkt):
   print pkt.summary()
   return
sniff(iface= sys.argv[1], count=int(sys.argv[2]), prn=PacketHandler)

Now I get an ImportError:

Traceback (most recent call last):
 File "./packethandler.py", line 3, in <module>
   from scapy.all import *
ImportError: No module named scapy.all
Reply
#4
Make sure it's installed and import it properly
Reply
#5
(01-03-2021, 06:04 PM)poppopret Wrote: Make sure it's installed and import it properly

Thanks, I’ll let you know how I got on
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Ebook Collection [89 Files] Insider 15 88,552 08-12-2021, 08:02 PM
Last Post: zzeuss
  NSA Python Training Insider 4 29,014 08-12-2021, 02:14 AM
Last Post: hworth
  What’s the issue here ? FancyBear 4 22,604 01-13-2021, 06:50 PM
Last Post: Vector
  Python Data structures and algorithms resources skinnyj0shua 1 17,485 12-23-2020, 12:52 PM
Last Post: enmafia2