I'm testing running simple script to ping few servers by calling a text file iplist.txt. The script working if txt file only contain IP address. Now I'm adding hostname next to the IP address in the iplist.txt and ping failed.
Original only IP address in iplist.txt
192.168.1.1
192.168.1.2
Updated with name string in iplist.txt
192.168.1.1 server1
192.168.1.2 server2
I think the issue is the strip part,
def iplist() :
# Grab list of IP from the file
pingList = open("iplist.txt", "r")
for i in pingList:
ip = i[-15:]
ip = ip.strip(' ')
ip = ip.strip('\n')
with open(os.devnull, 'w') as DEVNULL:
try:
subprocess.check_call(
['ping', '-w', '1', ip],
stdout = DEVNULL,
stderr = DEVNULL
)