Modify this script (pinging a machine)

bsharath
bsharath used Ask the Experts™
on
Hi,

I have this script which takes the machine names from a file and pings the machines and gives me the output to a excel sheet with the report if the machine is online or offline.

Set objExcel = CreateObject("Excel.Application")

objExcel.Visible = True

objExcel.Workbooks.Add

intRow = 2



objExcel.Cells(1, 1).Value = "Machine Name"

objExcel.Cells(1, 2).Value = "On Line"

objExcel.Cells(1, 3).Value = "Off Line"


Set Fso = CreateObject("Scripting.FileSystemObject")

Set InputFile = fso.OpenTextFile("servers.txt")



Do While Not (InputFile.atEndOfStream)

HostName = InputFile.ReadLine



Set WshShell = WScript.CreateObject("WScript.Shell")

Ping = WshShell.Run("ping -n 1 " & HostName, 0, True)



objExcel.Cells(intRow, 1).Value = HostName



Select Case Ping

Case 0 objExcel.Cells(intRow, 2).Value = "On Line"

Case 1 objExcel.Cells(intRow, 3).Value = "Off Line"

End Select



intRow = intRow + 1

Loop



objExcel.Range("A1:B1:C1").Select

objExcel.Selection.Interior.ColorIndex = 19

objExcel.Selection.Font.ColorIndex = 11

objExcel.Selection.Font.Bold = True

objExcel.Cells.EntireColumn.AutoFit


Can i have the ip address also of the machine that this script is pinging next to the stautus

Regards
Sharath
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
I tried using this on my version of Excel and it doesn't work for me but it's interesting you need something like this as I coded something for my use in Delphi on Friday.

I would think you might need a 3rd party component to lookup the IP from the machine name
(you could try just putting the variable PING out to a cell - maybe it holds the output of the ping command.
I'm sorry I'm not an expert at this scripting)

At the moment it takes a machine name or IP (or mix) list and pings each one and puts a passed or fail back in the window.

I didn't think to try using Excel etc but it works fairly well for me.

At the moment it doesn't save the results for me but that would only be a 10 second change.
(if you wanted a copy it would be possible to tidy it up and give you a copy as is - No warrenty, no support etc etc)

Let me know.
Aik

Author

Commented:
Can you give me a copy?
Yes. It's Nearly home time for me but I could Tidy it up, and add the ability to save the results to file.
I could then give you a copy sometime tomorrow.

Would that be ok?
(Maybe someone else will come up with a solution for your scripting in the mean time.)

Aik
CompTIA Security+

Learn the essential functions of CompTIA Security+, which establishes the core knowledge required of any cybersecurity role and leads professionals into intermediate-level cybersecurity jobs.

Author

Commented:
Ok no problem
I'm currently working on uploading this file so you can download it.

Aik

Author

Commented:
Ok ...
I've uploaded the program to:
http://www.yousendit.com/download/UVJqV0o1TlFYSHcwTVE9PQ
(You have 7 days to download it)

It's called pinger.exe

The input IP/Hostnames need to be in a file called IPLIST.txt in the same directory as the executable.
One IP/Hostname per line.
No blank spaces.

If you save the results they save to two files, IPLISTOUT.TXT and IPLISTDETAIL.TXT.

It's sometimes possible the program gets invalid data back from a ping and it causes the program to go screwy... :-( But if you just reload the IP list and click ping again you should be ok.
(if not the ever useful, close it and try again should do the trick)

Remember it's provided as is and has been done in my own time and there's no warranty or support agreement attached to this program.

I hope you find it useful.

Aik

Author

Commented:
I have downloaded the file.What is the ext of that file.how can i execute the file
It's an executable - the filename is pinger.exe and you run it like any other windows application.
Double click it.

Or

Start > Run > "Saved Location"\pinger.exe

Aik

Author

Commented:
I have download the file but it shoows unknown file type and the size is 443 kb.
The file I have is and executable and is about 430KB.

If it doesn't work by adding the extension of EXE, look in my profile and you'll find a way to e-mail me.
E-mail me and I'll e-mail a copy of the program back to you.
(As per EE's rules don't use this e-mail address for any further questions, continue to ask on EE)

Thanks,

Aikidoka

Author

Commented:
Ok

Author

Commented:
I have just sent you a email
Nothing Recieved as yet.

Can you please check and try again?
If it's still a problem just add your details to your profile and I'll try and contact you.

Aik

Author

Commented:
Resent to the correct address please chk now

Author

Commented:
Did you get the mail
Yes. I replied at about 7PM yesterday.

(Check it didn't get stopped by your mail filters at your work as I sent it as a zipped executable)

Aik

Author

Commented:
Can you sent it to this address.

nnnn@nnn.com
done

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial