Advertisement
Guest User

islive.py

a guest
Dec 18th, 2024
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. import socket
  2. import sys
  3. import time
  4.  
  5. def isOpen(ip):
  6.   s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  7.   try:
  8.     s.connect_ex((ip, int(22)))
  9.     s.shutdown(2)
  10.     return True
  11.   except:
  12.     return False
  13.  
  14. start = time.process_time()
  15. timeout = int(sys.argv[2])
  16.  
  17. while True:
  18.   if isOpen((sys.argv[1])):
  19.     print(f"Success ... found host {sys.argv[1]} after %s seconds" % str(round((time.process_time()-start)*1000,1)))
  20.     exit()
  21.   else:
  22.     if (time.process_time()-start)*1000>timeout:
  23.       print(f"Timed out - {sys.argv[1]}")
  24.       exit()
  25.     print(f"Sleeping...%s seconds elapsed for host {sys.argv[1]}" % str(round((time.process_time()-start)*1000,1)))
  26.     time.sleep(0.25)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement