Sinffer with Pcapy

#!/usr/bin/env python
import sys
import pcapy
from impacket . ImpactDecoder import EthDecoder , LinuxSLLDecoder
 
devs = pcapy . findalldevs ()
print " Devices List ―> "
for i in devs :
    
print " <%s>Dev:%s,Network:%s " % ( devs . index ( i ) , i , pcapy . open_live ( i , 0 , 0 , 0 ) . getnet ())
idx = raw_input ( " Your choice : " )
dev = devs [ int ( idx )]
#
p = pcapy . open_live ( dev , 1500 , 0 , 100 )
p . setfilter ( )
print " Listening on %s " % dev
# define a decoder to decode data
decoder = EthDecoder ()
if pcapy . DLT_LINUX_SLL == p . datalink :
    
decoder = LinuxSLLDecoder ()
#
def pk ( hdr , data ) :
    
print decoder . decode ( data )
try :
    
p . loop ( 0 , pk )
except KeyboardInterrupt :
    
print " Terminated by user ! "
    
sys . exit ( 0 )

你可能感兴趣的:(职场,休闲,sinffer,Pcapy)