![]() ![]() ![]() Parser.add_argument("-filter", "-f", help='BPF formatted packet filter.', default="tcp and port 80") Parser.add_argument("-interface", "-i", help="Which interface to sniff on.", default="eth0") # Parser command line arguments and make them available.įormatter_class=argparse.ArgumentDefaultsHelpFormatter,ĭescription="Print HTTP Request headers (must be run as root or with capabilities to sniff).", ("You can install it by running: sudo pip install -U 'scapy>=2.3,=1.8'") ![]() ("ERROR: You must have scapy installed.\n") # Try to import sniff from scapy.all and show error w/ install instructions if it cannot be imported. Logging.getLogger("ntime").setLevel(logging.ERROR) This needs to be done before the import from scapy. # Suppress scapy warning if no default route for IPv6. Aside from the formatting, this seems like the most efficient means posted on this question so far and you can delegate to a function to add formatting and further deconstruct the dict. This won't have the asterisk packet breaks but instead just prints the headers as pretty printed dictionary so this may work for you or may not but you can also customize it to suit your needs. I had commented on one way to improve it but I decided to whip together a more complete solution. You also need to split the string returned from it and join it back together with newline characters, otherwise it spits it out all on one line: #!/usr/bin/python You need to use the sprintf function of the packet instead of printing the packet itself. I am trying to code a simple sniffer in Scapy, which only prints HTTP packets with GET method only. ![]()
0 Comments
Leave a Reply. |