I'm writing a small script, that gathers some information using scapy and then returns some xml code, that I'll pass on to the xmlrpc interface of metasploit. I'd like it that my script only returns xml, and no additional warnings etc.
I can suppress most scapy output, with adding the option verbose=0
to my sr1 command. What I still get before every output, and I assume it returns this warning when I'm loading the module, is:
WARNING: No route found for IPv6 destination :: (no default route?)
I can easily redirect that output, by calling my script like this:
./myscript 2> /dev/null
but I'd like to incorporate this into the script. For that I've found a hint, that one could have a NullDevice class, that doesn't write anything, and then set sys.stderr
to an instantiation of that NullDevice class.
This only works unfortunately after I've already loaded the module, so I still have the Warning, and it only redirects any following messages sent to stderr.
How can I suppress that warning message to appear on my screen?
You can get rid of warnings by scapy by adding:
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
before importing Scapy. This will suppress all messages that have a lower level of seriousness than error messages.
for example:
import logging
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
from scapy.all import *
...
I think this is the correct way.
>>> import sys
>>> sys.stderr = None # suppress stderr
>>> from scapy.all import *
>>> sys.stderr = sys.__stderr__ # restore stderr
>>> print("other errors can be shown", file=sys.stderr)
other errors can be shown
>>>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With