sniffer un packet en python
Bonjour
Je tente de faire un script pour surveiller le flux reseau.
Quand j'execute le script ci dessous :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
#!/usr/bin/python
import pcapy
import impacket.ImpactDecoder as Decoders
import impacket.ImpactPacket as Packets
print 'Opening eth0s'
cap = pcapy.open_live('eth0', 5000, 1, 0)
eth_decoder = Decoders.EthDecoder()
ip_decoder = Decoders.IPDecoder()
(header, payload) = cap.next()
while (header):
(header, payload) = cap.next()
ethernet = eth_decoder.decode(payload)
if ethernet.get_ether_type() == Packets.IP.ethertype:
ip = ip_decoder.decode(payload[ethernet.get_header_size():])
ip_src = ip.get_ip_src()
ip_dst = ip.get_ip_dst()
print 'ip dest : %s'%ip_dst |
sur un raspberry ca marche bien (J'ai des IP qui sortent)
Par contre quand je l'execute sur une autre machine ubuntu j'ai le message d'erreur suivant :
Code:
1 2 3
|
(header, payload) = cap.next()
socket.timeout: timed out |
si je modifie le code avec un try/except autour de "(header, payload) = cap.next()" ca marche bien.
Mais c'est moins propre...
Comme si dans un cas la commande cap attend d'avoir quelque chose et dans l'autre comme il n'y a pas de trafic elle plante...
Une idee sur ce pb ?
Merci