| 41 | |
| 42 | |
| 43 | def windows(): # This is the function to run if it detects the OS is windows. |
| 44 | f = open(outputfile, "a") # Open the logfile |
| 45 | for server in open(serverfile, "r"): # Read the list of servers from the list |
| 46 | # ret = subprocess.call("ping -n 3 %s" % server.strip(), shell=True,stdout=open('NUL', 'w'),stderr=subprocess.STDOUT) # Ping the servers in turn |
| 47 | ret = subprocess.call( |
| 48 | "ping -n 3 %s" % server.strip(), |
| 49 | stdout=open("NUL", "w"), |
| 50 | stderr=subprocess.STDOUT, |
| 51 | ) # Ping the servers in turn |
| 52 | if ret == 0: # Depending on the response |
| 53 | f.write( |
| 54 | "%s: is alive" % server.strip().ljust(15) + "\n" |
| 55 | ) # Write out to the logfile is the server is up |
| 56 | else: |
| 57 | f.write( |
| 58 | "%s: did not respond" % server.strip().ljust(15) + "\n" |
| 59 | ) # Write to the logfile if the server is down |
| 60 | |
| 61 | |
| 62 | def linux(): # This is the function to run if it detects the OS is nix. |