
Originally Posted by
senator1983
DanceswithUnix,
Unfortunately I am just a field technician, I lack the necessarry permissions to install or run unauthorized software on our PCN or Process Control Network servers. I am sure it is obvious that I know very little about programming or writing code, is Python or Ruby going to require installation on the machine running the script?
Thank you for your feedback
I feel for you, yes many of us have been there.
Sometimes some idiot even trots out the "A good workman never blames his tools" line. A hundred years ago if you wanted to learn something like carpentry then you did an apprenticeship and as part of that *you made your own tools*, so yes a good workman doesn't blame them partly because they are his and partly because he knows which one he should use. A bad workman blames the tools because, no that's not a hammer, that's a screwdriver.
You are trying to hammer something in with a lump of lard. You might get there in the end, but really, ask what is acceptable to put on a machine, if there is any wiggle room at all.
Here is the answer in Python. I tried it in Windows 7, it coped with a live host, an unreachable host and a timed out host. I left a trap in there for "Unknown" if the parsing fails to try and avoid false reports. The world is a nicer place if you don't smother it with goto statements 
Edit to add: I believe Python programs can be compiled into an ".exe" file, in theory that is no more dangerous than running your .cmd script on a machine as you compiled it. Perhaps you could run that instead of your script?
My Python is really rusty, but I knocked this out in about half an hour including installing Python and finding a tutorial on how to run the "idle" environment for writing and debugging it.
from subprocess import Popen, PIPE
reportFile = open( "report.txt", "w" )
for hostLine in open( "AWTPLCs.txt" ):
splitLine = hostLine.strip().split( ":" )
hostName = splitLine[0]
hostIP = splitLine[1]
print( "Testing "+hostIP )
cmd = Popen("ping -n 1 "+hostIP, stdout=PIPE)
for line in cmd.stdout:
if "time=" in str( line ):
hostState = "Alive"
break
elif "unreachable" in str( line ):
hostState = "Down"
break
elif "timed out" in str( line ):
hostState = "Down"
break
else:
hostState = "Unknown"
reportFile.write( hostName + " is " + hostState + "\n" )
reportFile.close()