I need help on looping all my list and print my list name. Currently, I have a few raspberry pi types and windows PC. I am trying to ping all my pi and windows and get the responses below are some of what I have tried
question is how to loop, piserver, pi2b,pi2,pi3,pi4 and windows
import platform
plat = platform.system()
piservers = {"10.10.10.115", "10.10.10.125", "10.10.10.135", "10.10.10.145", "10.10.10.165", "10.10.10.175", "10.10.10.185"}
pi2b= {"10.10.10.111", "10.10.10.112", "10.10.10.113", "10.10.10.114"}
pi2 = {"10.10.10.121", "10.10.10.122", "10.10.10.123", "10.10.10.124"}
pi3 = {"10.10.10.131", "10.10.10.132", "10.10.10.133", "10.10.10.134"}
pi4 = {"10.10.10.141", "10.10.10.142", "10.10.10.143", "10.10.10.144"}
Windows = {"10.10.10.151", "10.10.10.152", "10.10.10.153", "10.10.10.154"}
for vm in piservers :
# Check for Windows and Linux Platforms
if plat == "Windows":
response = os.system("ping -n 1 " + vm)
pass
elif plat == "Linux":
response = os.system("ping -c 1 -W 3 " + vm)
pass
#and then check the response...
if response == 0:
print ("***********************************")
print(vm, 'is UP!')
print ("***********************************")
print ("\n")
elif response == 2 or 256 or 512:
print ("***********************************")
print(vm, 'is DOWN and No response from Server!')
print ("***********************************")
print ("\n")
else:
print ("***********************************")
print(vm, 'is DOWN!')
print ("***********************************")
print ("\n")
Select the correct answer from above options