Différences
Ci-dessous, les différences entre deux révisions de la page.
| Prochaine révision | Révision précédente | ||
| scripts:python:scanner_ip [2019/05/04 16:31] – créée Marc Fournier | scripts:python:scanner_ip [2020/10/03 09:26] (Version actuelle) – FabLac | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| ====== Scanner IP ====== | ====== Scanner IP ====== | ||
| - | ===== Scripts | + | ===== Script |
| - | ** Usage** | + | === Usage : === |
| - | Usage: | + | < |
| + | |||
| + | === Options: === | ||
| - | Options: | ||
| < | < | ||
| -i IP, --ip=IP | -i IP, --ip=IP | ||
| Ligne 21: | Ligne 22: | ||
| < | < | ||
| - | Scanner | + | Scanner |
| - | < | + | < |
| + | |||
| + | |||
| + | === code source : scan-ip.py === | ||
| + | < | ||
| + | |||
| + | infos =''' | ||
| + | ###################################################### | ||
| + | |||
| + | --- OPTIONS et USAGE --- | ||
| + | |||
| + | python scan-ip.py [options] | ||
| + | options : -h, -i, -t, -o, -n | ||
| + | |||
| + | Exemples : | ||
| + | python scan-ip.py --help | ||
| + | |||
| + | python scan-ip.py -i 192.168.1.1-254 | ||
| + | |||
| + | ------------------------------------------------------ | ||
| + | |||
| + | ###################################################### | ||
| + | ''' | ||
| + | # ==================================================== | ||
| + | # usage des options | ||
| + | usage = " | ||
| + | |||
| + | # ==================================================== | ||
| + | |||
| + | # Importation des Modules | ||
| + | import os | ||
| + | import multiprocessing | ||
| + | import time | ||
| + | import optparse | ||
| + | import platform | ||
| + | |||
| + | |||
| + | # Ping | ||
| + | class PingScan: | ||
| + | def __init__(self, | ||
| + | self.start_time=time.time() | ||
| + | self.collect_ip=multiprocessing.Queue() | ||
| + | self.target=target | ||
| + | self.thread=thread | ||
| + | self.output=output | ||
| + | self.timeout=timeout | ||
| + | self.set_os_command() | ||
| + | self.multi_scan() | ||
| + | |||
| + | # Sauvegarde Output | ||
| + | def save_output(self): | ||
| + | f=open(self.output,' | ||
| + | for i in self.collect_ip: | ||
| + | | ||
| + | f.close() | ||
| + | return | ||
| + | |||
| + | # Multi_processing | ||
| + | def multi_scan(self): | ||
| + | proces=[] | ||
| + | for ip in self.target: | ||
| + | | ||
| + | if k==self.thread: | ||
| + | time.sleep(3) | ||
| + | self.thread=self.thread+30 | ||
| + | | ||
| + | | ||
| + | | ||
| + | |||
| + | for mythread in proces: | ||
| + | | ||
| + | self.endtime=time.time() | ||
| + | self.affichage_resultats() | ||
| + | return | ||
| + | |||
| + | # Affichage | ||
| + | def affichage_resultats(self): | ||
| + | sauvegarde_ip=[] | ||
| + | x=1 | ||
| + | while x==1: | ||
| + | | ||
| + | sauvegarde_ip.append(self.collect_ip.get_nowait()) | ||
| + | | ||
| + | x=x+1 | ||
| + | self.collect_ip=sauvegarde_ip | ||
| + | |||
| + | print " | ||
| + | print "[+] Demarrage Scan \t\t: | ||
| + | print "[+] Fin du Scan \t\t: | ||
| + | print "[+] Duree Totale du scan \t: | ||
| + | print "[+] Nombre Adresses IP Actives\t: | ||
| + | if self.output: | ||
| + | | ||
| + | return | ||
| + | |||
| + | # Selection de commande selon OS | ||
| + | def set_os_command(self): | ||
| + | oper = platform.system() | ||
| + | if (oper==" | ||
| + | ping = "ping -n {} {}" | ||
| + | elif (oper== " | ||
| + | ping= "ping -c {} {}" | ||
| + | else : | ||
| + | ping= "ping -c {} {}" | ||
| + | self.commad=ping | ||
| + | return | ||
| + | |||
| + | # Status IP | ||
| + | def checkping(self, | ||
| + | ping=self.commad | ||
| + | recv=os.popen(ping.format(self.timeout, | ||
| + | recv=recv.upper() | ||
| + | if recv.count(' | ||
| + | print "[+]\t {} \t==> IP Active " | ||
| + | | ||
| + | return | ||
| + | |||
| + | |||
| + | # Extraction plage IP | ||
| + | def extraction(plage): | ||
| + | | ||
| + | if plage: | ||
| + | # Verification plage IP | ||
| + | if " | ||
| + | | ||
| + | | ||
| + | elif "," | ||
| + | | ||
| + | elif "," | ||
| + | | ||
| + | for i in plage.split(',' | ||
| + | if ' | ||
| + | | ||
| + | | ||
| + | else: | ||
| + | | ||
| + | | ||
| + | else: | ||
| + | | ||
| + | | ||
| + | pass | ||
| + | | ||
| + | |||
| + | # Extraction adresse IP | ||
| + | def IP_extractor(ip): | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | for i1 in x1: | ||
| + | for i2 in x2: | ||
| + | for i3 in x3: | ||
| + | for i4 in x4: | ||
| + | | ||
| + | | ||
| + | |||
| + | def main(): | ||
| + | CBLUE = ' | ||
| + | CEND = ' | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | if not options.ip: | ||
| + | print "[+] Indiquez une plage IP, ex: scan-ip.py -i 192.168.1.1-254 " | ||
| + | exit(0) | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| - | **scan-ip.py** | + | if __name__ == ' |
| - | < | + | |
| + | </ | ||