Just like the title says, I need to be pointed in the right direction on this. I'm not looking for "Here's your code" (I recently began coding in Python, so my understanding is at very basic level)
But basically I will have a txt file full of hostnamnes (one on each row) that I need to ping to see if they are 1. Active and 2. What the IP-address of that active hostname is. And then I need the program to output the hostname + IP to a txt file.
I read up a bit on the subject and it seems that subprocess is the way to go. Time isn't really relevant so I don't need it to multi thread.
So in conclusion, any good tips on where to begin (so that I may understand what I'm typing)?
EDIT:: So this is how far i have gotten:
import ping, socket
hostsFile = open('hostnames.txt', 'r')
lines = hostsFile.readlines()
addr = socket.gethostbyname(lines)
for lines in hostsFile:
print 'IP-address of', hostname
print 'is', addr
try:
ping.verbose_ping(count=3)
delay = ping.Ping(timeout=2000).do()
except socket.error, e:
print "Ping Error:", e
It now returns an error referring to the addr = socket.gethostbyname(lines) line, saying: "TypeError: must be string, not list"
While i do understand the error somewhat, i have no idea how to get around it.