0

I am currently working with Scapy and encounter the error:

NameError: global name 'Scapy_Exception' is not defined

I have 2 options: To either catch the error and convert the capture file into pcap on the fly using:

tshark -F libpcap -w <outfile> -r <infile>

or have scapy read capture files in other format. Can I know:

  1. How do I catch Scapy_Exception?

  2. How to read capture files in scapy other than the .pcap format?

  3. Which of the above options will be better?

Thanks!

krish7919
  • 892
  • 2
  • 13
  • 30
  • This is what happens when I try: `try: pkts=rdpcap('/home/krish/Desktop/captures/invalid_for_scapy/dicom_42.cap') except scapy.error.Scapy_Exception as msg: print msg` `NameError: global name 'Scapy_Exception' is not defined` – krish7919 Nov 29 '12 at 18:00
  • First time ever that a questions taking so long to be answered on SO, I guess.. :) – krish7919 Nov 30 '12 at 17:31

1 Answers1

0

Ok, after playing around a little bit, I added the line

from scapy.error import Scapy_Exception in the file utils.py and ran my program.

It catches the error now if I do:

try:
   ...:     pkts = rdpcap('./ms_dns.enc')
   ...: except Scapy_Exception as msg:
   ...:     print msg, "Hi there!!"
   ...: 
         Not a pcap capture file (bad magic) Hi there!!

So now I can catch the error and convert the file on the fly and use it.

Thanks!

krish7919
  • 892
  • 2
  • 13
  • 30
  • How did you fix the error about the invalid pcap file? I have generated a file via tshark but I get the same error. – zengr Jul 28 '13 at 06:05
  • I cannot comment here with my complete code (it says 67 characters too long). Basically, I catch the scapy_exception, then convert the file to a pcap format using the command in my question. Then I read this file rather than the original file and it should succeed. If it doesn't then the capture file could not be converted! – krish7919 Jul 29 '13 at 07:44