Guest User

Untitled

a guest
Jul 7th, 2021
24,986
2
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 2 0
  1. #!/usr/bin/python3
  2. #coding: utf-8
  3.  
  4. import re, sys, subprocess
  5.  
  6. # python3 wichSystem.py 10.10.10.188
  7.  
  8. if len(sys.argv) != 2:
  9.     print("\n[!] Uso: python3 " + sys.argv[0] + " <direccion-ip>\n")
  10.     sys.exit(1)
  11.  
  12. def get_ttl(ip_address):
  13.  
  14.     proc = subprocess.Popen(["/usr/bin/ping -c 1 %s" % ip_address, ""], stdout=subprocess.PIPE, shell=True)
  15.     (out,err) = proc.communicate()
  16.  
  17.     out = out.split()
  18.     out = out[12].decode('utf-8')
  19.  
  20.     ttl_value = re.findall(r"\d{1,3}", out)[0]
  21.  
  22.     return ttl_value
  23.  
  24. def get_os(ttl):
  25.  
  26.     ttl = int(ttl)
  27.  
  28.     if ttl >= 0 and ttl <= 64:
  29.         return "Linux"
  30.     elif ttl >= 65 and ttl <= 128:
  31.         return "Windows"
  32.     else:
  33.         return "Not Found"
  34.  
  35. if __name__ == '__main__':
  36.  
  37.     ip_address = sys.argv[1]
  38.  
  39.     ttl = get_ttl(ip_address)
  40.  
  41.     os_name = get_os(ttl)
  42.     print("\n%s (ttl -> %s): %s\n" % (ip_address, ttl, os_name))
Advertisement
Comments
  • klerick
    1 year
    # text 0.12 KB | 0 0
    1. me sale este error zsh: /usr/bin/whichSystem.py: bad interpreter: /usr/bin/python3^M: no existe el fichero o el directorio
Add Comment
Please, Sign In to add comment