you have already spent some time getting into the nuts and bolts of sniffing in python so let' get to know scapy' interface for sniffing packets and dissecting their contents we are going to build very simple sniffer to capture smtppop and imap credentials laterby coupling our sniffer with our address resolution protocol (arppoisoning man-in-the-middle (mitmattackwe can easily steal credentials from other machines on the network this technique can of course be applied to any protocol or to simply suck in all traffic and store it in pcap file for analysiswhich we will also demonstrate to get feel for scapylet' start by building skeleton sniffer that simply dissects and dumps the packets out the aptly named sniff function looks like the followingsniff(filter="",iface="any",prn=function,count=nthe filter parameter allows us to specify bpf (wireshark-stylefilter to the packets that scapy sniffswhich can be left blank to sniff all packets for exampleto sniff all http packets you would use bpf filter of tcp port the iface parameter tells the sniffer which network interface to sniff onif left blankscapy will sniff on all interfaces the prn parameter specifies callback function to be called for every packet that matches the filterand the callback function receives the packet object as its single parameter the count parameter specifies how many packets you want to sniffif left blankscapy will sniff indefinitely let' start by creating simple sniffer that sniffs packet and dumps its contents we'll then expand it to only sniff email-related commands crack open mail_sniffer py and jam out the following codefrom scapy all import our packet callback def packet_callback(packet)print packet show(fire up our sniffer sniff(prn=packet_callback,count= we start by defining our callback function that will receive each sniffed packet and then simply tell scapy to start sniffing on all interfaces with no filtering now let' run the script and you should see output similar to what you see below python mail_sniffer py warningno route found for ipv destination :(no default route?###ethernet ]##dst : : :ab: : src : : :ff: : type ###ip ]##version ihl tos len id flags df frag ttl proto tcp chksum src dst \options ###tcp ]##