Advertisement
Guest User

Ping IP addresses array

a guest
Oct 21st, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. from termcolor import colored
  5. import subprocess
  6.  
  7.  
  8. iplist=["172.16.30.1","8.8.8.8","20.1.20.33"]
  9.  
  10.  
  11. def runTests():
  12.   for ip in iplist:
  13.     address = ip
  14.     res = subprocess.call(['ping', '-c', '3', '-W', '1', address],stdout=subprocess.PIPE)
  15.     if res == 0:
  16.         print colored("✔️ " + address, 'green')
  17.     elif res == 2:
  18.         print colored("❌  " + address + " aucune réponse", 'yellow')
  19.     else:
  20.         print colored("❌  " + address, 'red')
  21.  
  22.  
  23. runTests()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement