[Python] Scapy - Scan arping rapide - thxer - 21-05-2013
Coucou je débute avec scapy pour développer mes propres tools.
Je poste ici le code pour d'une part partager même si il n'y a rien de compliqué mais surtout pour apprendre à coder mieux.
Comment optimiser / raccourcir mon code ?
Code PYTHON :
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from os import (popen)
from scapy.all import (arping , ARP, Ether, srp)
# Ici c'est ma fonction permettant de gerer le resultat des reponses des paquets envoyés par scapy
def affiche(ip,ans1):
p = ans,unans =srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst=ip),timeout=2)
os.system("clear")
ans1.summary(lambda (s,r): r.sprintf("\033[1;35m \n\n Mon Adresse mac: \033[1;m\033[1;37m %ARP.hwdst% \033[1;m \n"))
print ("\nResultat du scan : ")
ans.summary(lambda (s,r): r.sprintf("\033[1;35mAdresse Mac:\033[1;m \033[1;37m %Ether.src% \033[1;m \033[1;35mIp:\033[1;m \033[1;37m %ARP.psrc% \033[1;m\n") )
# Debut du script // Il demande la plage d'adresse
print "\033[1;35m-------------- Scan Rapide Par ping du Arp ----------------------- \n\033[1;m \033[1;37m freecr@ck \033[1;m "
print "\nQuel plage d'adresses ? (Pour 192.168.1.0/24 tapez 'Entrer')\n "
ip = raw_input ("\n-192.168.1.* (default) => ")
ans1, unans = srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst="192.168.1.1"),timeout=2)
if (ip == "" ) :
ip = "192.168.1.0/24"
affiche(ip,ans1)
else :
ip = ip+"/24"
affiche(ip,ans1)[/php]
RE: [Python] Scapy - Scan arping rapide - fr0g - 22-05-2013
Un peu modifié (suppression de quelques variables pas forcement utiles) 
Code PYTHON :
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os
from scapy.all import (arping , ARP, Ether, srp)
def affiche(ip,ans1):
p = ans, unans = srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst=ip),timeout=2)
os.system("clear")
ans1.summary(lambda (s,r): r.sprintf("\033[1;35m \n\n Mon Adresse mac: \033[1;m\033[1;37m %ARP.hwdst% \033[1;m \n"))
print ("\nResultat du scan : ")
ans.summary(lambda (s,r): r.sprintf("\033[1;35mAdresse Mac:\033[1;m \033[1;37m %Ether.src% \033[1;m \033[1;35mIp:\033[1;m \033[1;37m %ARP.psrc% \033[1;m\n") )
print """
\033[1;35m-------------- Scan Rapide Par ping du Arp ----------------------- \n
\033[1;m \033[1;37m freecr@ck \033[1;m
\nQuel plage d'adresses ? (Pour 192.168.1.0/24 tapez 'Entrer')\n
"""
ans1, unans = srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst="192.168.1.1"),timeout=2)
if (raw_input ("\n-192.168.1.* (default) => ") == "" ): affiche("192.168.1.0/24",ans1)
else : affiche(ip+"/24",ans1)
RE: [Python] Scapy - Scan arping rapide - thxer - 22-05-2013
Super ! merci
|