Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. import subprocess
  2. # empty list that will store ping results
  3. ping_result = "\n\n"
  4. #ping size can be adjusted by changing the number here"(["ping", "-c 2", address])"
  5. with open('devices.txt') as f:
  6. for line in f:
  7. address = line.strip("\n")
  8.  
  9. #res = subprocess.call(["ping", "-n 2", address])
  10. res = subprocess.call(["ping", address])
  11. if res == 0:
  12. ping_result = ping_result + "ping to " + address + " OK" + " \n"
  13. elif res == 2:
  14. ping_result = ping_result + "no response from " + address + " \n"
  15. else:
  16. ping_result = ping_result + "ping to " + address + " failed!" + " \n"
  17.  
  18. #python3
  19. print (ping_result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement