Ping VB Script

How to get ping result like packets sent received lost percent in vbs. Want to ping many hosts from a file want to gather above data in a text file.
LVL 10
MuraliAsked:
Who is Participating?
 
exx1976Connect With a Mentor Commented:
Here you go.  It expects an input text file at   c:\iplist.txt      that has one IP address per line.

Output will be a csv file  formatted as follows:

IP,host name, ping statistics


HTH,
exx
Set oWS = CreateObject("WScript.Shell")
Set oFS = CreateObject("Scripting.FileSystemObject")
Set inFile = oFS.OpenTextFile("C:\IPlist.txt")
Set outFile = oFS.CreateTextFile("C:\names.csv")
Do While Not inFile.AtEndOfStream
	write = ""
	IP = inFile.ReadLine
	cmd = "ping -a " & IP
	Set ExecOutput = oWS.Exec(cmd)
	Set Output = ExecOutput.StdOut
	While Not Output.AtEndOfStream
		data = Output.ReadLine
		If Left(data,7) = "Pinging" Then
			name = Split(data," ")
			write = IP & "," & name(1) & ","
		End If
		If InStr(data,"Packets:") Then
			write = write & Left(Right(data,Len(data)-4),Len(Right(data,Len(data)-4))-2)
			outFile.WriteLine(write)
		End If
	Wend
Loop
inFile.Close
outFile.Close

Open in new window

0
 
exx1976Commented:
Have you tried this yet?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.