DarkProgrammer000

Scan IP+Host

Aug 4th, 2021
690
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. """
  2. Programa: Scanner utilizando o 'ping'
  3. """
  4.  
  5. # Bibliotecas
  6. from os import system
  7. from ipaddress import ip_address
  8.  
  9. def apresentacao():
  10.  
  11.     # Comando de sistema
  12.     system("clear")
  13.     print("\033[01;31m # DARK PROGRAMMER 000 \033[01;37m")
  14.  
  15.     print("\n ===== PORT SCAN ===== \n")
  16.     system("echo -n ' # IP [externo]: '")
  17.     system("curl ifconfig.me --silent | awk {'print $1'}")
  18.  
  19.     system("echo -n ' # IP [interno]: '")
  20.     system("hostname -I | awk {'print $1'}")
  21.     print('''\033[01;32m
  22.                   ..:::::::::..
  23.                  ..:::aad8888888baa:::..
  24.              .::::d:?88888888888?::8b::::.
  25.            .:::d8888:?88888888??a888888b:::.
  26.          .:::d8888888a8888888aa8888888888b:::.
  27.         ::::dP::::::::88888888888::::::::Yb::::
  28.        ::::dP:::::::::Y888888888P:::::::::Yb::::
  29.       ::::d8:::::::::::Y8888888P:::::::::::8b::::
  30.      .::::88::::::::::::Y88888P::::::::::::88::::.
  31.      :::::Y8baaaaaaaaaa88P:T:Y88aaaaaaaaaad8P:::::
  32.      :::::::Y88888888888P::|::Y88888888888P:::::::
  33.      ::::::::::::::::888:::|:::888::::::::::::::::
  34.      ::::::::::::::::8888888888888b::::::::::::::'
  35.       :::::::::::::::88888888888888::::::::::::::
  36.        :::::::::::::d88888888888888:::::::::::::
  37.         ::::::::::::88::88::88:::88::::::::::::
  38.           ::::::::::88::88::88:::88::::::::::'
  39.             ::::::::88::88::P::::88::::::::'
  40.               ::::::88::88:::::::88::::::'
  41.                 ::::::::::::::::::::
  42.                       ::::::::::
  43.                       \033[01;37m''')
  44.  
  45. # Funcao: Endereco IP
  46. def qtdHost():
  47.     return int(input("\n# Quantidade de hosts: "))
  48.  
  49. # Funcao: Endereco IP
  50. def conversao():
  51.  
  52.     # Entrada de dados
  53.     strIP = input("# Digite IP [192.168.0.1]: ")
  54.  
  55.     # Transformando: String --> Ipv4
  56.     Ipv4 = ip_address(strIP)
  57.  
  58.     # Controle: Retornando ao ip passado
  59.     Ipv4 -= 1
  60.  
  61.     return Ipv4
  62.  
  63. # Funcao: Lista de IPs (255 hosts)
  64. def hosts(Ipv4, qtdHost):
  65.  
  66.     # Lista
  67.     listaIPv4 = []
  68.  
  69.     # Estrutura de repeticao
  70.     for i in range(0, qtdHost):
  71.  
  72.         # Somando 1 ao IP
  73.         Ipv4 += 1
  74.  
  75.         # Incremento lista
  76.         listaIPv4.append(Ipv4)
  77.  
  78.     return listaIPv4
  79.  
  80. def ping(listaIPv4, arq):
  81.  
  82.     # Sistema
  83.     system("clear")
  84.     print("\033[01;34m\n ===== PORT SCAN =====\n\033[01;37m")
  85.  
  86.     # Estrutura de repeticao
  87.     for i in range(0, len(listaIPv4)):
  88.  
  89.         # Retorno da resposta do codigo: Bash + Python
  90.         codigo = system("ping -c 1 -n -w1 " + str(listaIPv4[i]))
  91.  
  92.         if codigo == 0:
  93.  
  94.             # Escrevendo no 'arq'
  95.             arq.write("# %s\n" % listaIPv4[i])
  96.  
  97.             # Bash + Python
  98.             # system("echo " + str(listaIPv4[i]) + ": Ativo > relatorio.txt")
  99.  
  100.     # Mensagem: Relatorio
  101.     print("\033[01;34m# Relatorio concluido\033[01;37m")
  102.  
  103. # Metodo: Principal
  104. def main():
  105.  
  106.     # Tela inicial
  107.     apresentacao()
  108.  
  109.     # Arquivo
  110.     arq = open("relatorio.txt", "w")
  111.     arq.write("# %s\n\n" % "Lista de IPs Ativos")
  112.  
  113.     # Chamada de funcao
  114.     ping(hosts(conversao(),qtdHost()), arq)
  115.  
  116. # Execucao
  117. if __name__ == '__main__':
  118.  
  119.     try:
  120.         main()
  121.  
  122.     except Exception as erro:
  123.         print(erro)
RAW Paste Data