January 2019
Beginner to intermediate
776 pages
19h 58m
English
We can supply command-line arguments, for example, the network interface name and TCP port number, for sniffing.
Listing 8.1 gives the code for sniffing packets on your network, as follows:
#!/usr/bin/env python # Python Network Programming Cookbook, Second Edition -- Chapter - 8 # This program is optimized for Python 2.7.12. # It may run on any other version with/without modifications. import argparse import pcap from construct.protocols.ipstack import ip_stack def print_packet(pktlen, data, timestamp): """ Callback for priniting the packet payload""" if not data: return stack = ip_stack.parse(data) payload = stack.next.next.next print (payload) def main(): # setup commandline arguments parser = argparse.ArgumentParser(description='Packet ...
Read now
Unlock full access