Advertisement
Cirphelion

scanner©DM Version 2.0

Jul 5th, 2015
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.72 KB | None | 0 0
  1. #-------------------------------------------------------------------------------
  2. # Name:        scanner©DM Version 2.0
  3. # Purpose:     scan port et informations whois de la cible
  4. #
  5. # Author:      Cirphelion
  6. #
  7. # Created:     01/07/2015
  8. # Copyright:   (c) ©DM Version 2.0 2015
  9. # Licence:     ©DM Version 2.0
  10. #-------------------------------------------------------------------------------
  11. # -*- coding: cp-1252 -*-
  12. # -*- coding: utf-8 -*-
  13. import urllib
  14. import socket
  15. import subprocess
  16. import sys
  17. import os.path
  18. import errno
  19. from ipwhois import IPWhois
  20. from pprint import pprint
  21. from datetime import datetime
  22.  
  23. version = "\n                    ©DM Version 2.0"
  24.  
  25. # Scanner 2.0
  26. print ("-" * 60)
  27. print ("¤" * 60)
  28. print (version)
  29. print ("\nScan de Port Réseau Internet : A n'utiliser que pour soi-même")
  30. print ("\n                  ScanDM  FrameWork")
  31. print ("                    Version :  2.0 ")
  32. print ("                  Codename : Cirphelion\n")
  33. print ("¤" * 60)
  34. print ("-" * 60)
  35.  
  36. # Demande NDD ou IP pour le scanning
  37. try:
  38.     remoteServer    = input("Entrez l'IP ou le NDD a scanner (ex:google.fr): ")
  39.     remoteServerIP  = socket.gethostbyname(remoteServer)
  40. except KeyboardInterrupt:
  41.                 print ("\n[*]/!\ Arret /!\ ")
  42.                 sys.exit()
  43.  
  44. # liste des ports à choisir
  45. try:
  46.     min_port =input("Entrez un port de départ : ")
  47. except KeyboardInterrupt:
  48.                 print ("\n[*]/!\ Arret /!\ ")
  49.                 sys.exit()
  50. try:
  51.     max_port =input("Entrez un port de fin : ")
  52. except KeyboardInterrupt:
  53.                 print ("\n[*]/!\ Arret /!\ ")
  54.                 sys.exit()
  55.  
  56. # socket information
  57. TIMEOUT = 0.9 # modifiable facilement dans le programme
  58.  
  59. # Affecter à  min et max_port comme integrer
  60. min_port = int(min_port)
  61. max_port = int(max_port)
  62.  
  63. # scan Départ
  64. print ("-" * 60)
  65. print ("*" * 60)
  66. print ("        Please wait, scan en cours....", remoteServerIP)
  67. print ("*" * 60)
  68. print ("-" * 60)
  69.  
  70. # Temps de l'analyse
  71. t1 = datetime.now()
  72.  
  73. # Utilisation de la fonction de range pour spécifier les ports
  74. # Try et except pour intercepter les erreurs
  75. count_o = 0
  76. count_f = 0
  77. UNREACHABLE = 2 # inaccessible
  78. TIMEOUT_ERROR = 3 # connection non aboutie dans les temps TIMEOUT
  79. try:
  80.     for port in range(min_port,max_port):
  81.         sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  82.         sock.settimeout(TIMEOUT)
  83.         result = sock.connect_ex((remoteServerIP, port))
  84.         if result == 0:
  85.             print ("Port {}: \t Ouvert".format(port))
  86.             count_o = count_o + 1
  87.         else:
  88.             print ("Port {}: \t Fermé".format(port))
  89.             count_f = count_f + 1
  90.         sock.close()
  91.  
  92. except KeyboardInterrupt:
  93.     print ("Appuyer sur Ctrl+C")
  94.     sys.exit()
  95.  
  96. except socket.gaierror:
  97.     print ('NDD non résolue')
  98.     sys.exit()
  99.  
  100. except socket.error:
  101.     print ("connexion impossible vers le serveur")
  102.     sys.exit()
  103.  
  104. # Calcul du nouveau temps
  105. t2 = datetime.now()
  106.  
  107. # Calcule de la différence de temps, pour voir combien de temps il a fallu pour exécuter le script
  108. total =  t2 - t1
  109.  
  110. # Impression des informations à l'écran
  111. print ('Scanning finis en: ', total)
  112. print ("-" * 60)
  113. print ("")
  114. print ("Trouver %d ports ouverts" % (count_o,))
  115. print ("Trouver %d ports fermés \n" % (count_f,))
  116.  
  117. # IpWhois Scanner
  118. print ("-" * 60)
  119. print ("*" * 60)
  120. print ("Scanning Whois en Cours....please Wait")
  121. print ("-" * 60)
  122. print ("*" * 60)
  123. obj = IPWhois(remoteServerIP)
  124. results = obj.lookup(get_referral=True)
  125. pprint(results)
  126.  
  127. # Création du Fichier Texte de sortie-changement du path de sortie
  128. try:
  129.     NomFichier = input("Veuillez entrer un nom de fichier : ")
  130.     os.chdir('C:/Users/admin/Desktop/')
  131. except KeyboardInterrupt:
  132.     print ("Pas de Nom indiquer")
  133.     sys.exit()
  134.  
  135. # création et ouverture du fichier .txt en mode write 'w' (écriture)
  136. # si le fichier .txt existe déjà, il est écrasé
  137. try:
  138.     Fichier = open(NomFichier + ".txt",'w')
  139. except KeyboardInterrupt:
  140.     print ("Problème chemin Path")
  141.     sys.exit()
  142. # écriture dans le fichier avec la méthode write()
  143. Fichier.write("Scanner v2.0 by Cirphelion")
  144. Fichier.write("\n")
  145. Fichier.write("*" * 40)
  146. Fichier.write("\n")
  147. Fichier.write("Ports Découvert sur la cible")
  148. Fichier.write("\n")
  149. Fichier.write("-" * 40)
  150. Fichier.write("\n")
  151. for port in range(min_port,max_port) :
  152.     Fichier.write("Port {}: \t Ouvert \n".format(port))
  153. Fichier.write("\n")
  154. Fichier.write("*"*40)
  155. Fichier.write("\n")
  156. Fichier.write("Recherche Whois : ")
  157. Fichier.write("\n")
  158. Fichier.write("*"*40)
  159. Fichier.write("\n")
  160. Fichier.write(str(results)+"\n")
  161.  
  162. # fermeture du fichier avec la méthode close()
  163. Fichier.close()
  164.  
  165. # fichier créé
  166. print ("-" * 60)
  167. print ("*" * 60)
  168. print ("Votre Fichier est disponible sur votre bureau en .txt")
  169. print ("-" * 60)
  170. print ("*" * 60)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement