Avatar of jaw0807
jaw0807Flag for United States of America

asked on 

Resolve multiple hostnames to IP and ping tool, part II

I want a GUI tool that will read in a text file of hostnames and resolve the hostnames to IP addresses and then ping them.  The end result should be some sort of table with the hostname, IP address and the ping result (which could be just "No response" or "Response Rec'd" or similar).  Does anyone have any suggestions?  Or have any code?  The tool doesn't have to be free, if you know of a program that does it that would be fine.

Example:

PC1   192.168.1.100  No response
PC2   192.168.1.102  Response received
PC3   192.168.1.103  Response received
Windows OSNetwork Management

Avatar of undefined
Last Comment
DavidLeal
Avatar of sirbounty
sirbounty
Flag of United States of America image

Try this version...

'PingPCs.vbs
Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objShell: Set objShell = CreateObject("Wscript.shell")
Dim objExcell: Set objExcel = CreateObject("Excel.Application")
Dim objFile: Set objFile = objFSO.OpenTextFile("C:\PCList.txt")
Dim objWS, iRow

strReport = "C:\Output.xls"  'Output report

'Create and setup worksheet
objExcel.DisplayAlerts = 0
objExcel.Workbooks.Add
Set objWS = objExcel.ActiveWorkbook.Worksheets(1)
objWS.Name = "Ping Results"
Set Cells = objWS.Cells
With objWS
  .Cells(1, 1).Value = "ComputerName"
  .Cells(1, 2).Value = "IP Address"
  .Cells(1, 3).Value = "Response"
  .Range("A1:C1").Font.Bold = True
End With

iRow = 2
Do While Not objFile.AtEndOfStream
  strData = objFile.ReadLine
  Ping strData
Loop

objExcel.ActiveWorkbook.SaveAs strReport
objExcel.Quit

'Cleanup
Set objShell = Nothing
Set objWS = Nothing
Set objExcel = Nothing
WScript.Quit

Sub Ping(strPC)
On Error Resume Next
Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strPC & "\root\cimv2")
Set colItems = objWMI.ExecQuery("Select * from Win32_PingStatus Where Address = '" & strPC & "'")
strStatusCode = 1
For Each objItem In colItems
  With objWS
    strStatusCode = objItem.StatusCode
    .Cells(iRow, 1) = strPC
    .Cells(iRow, 2) = objItem.ProtocolAddress
    .Cells(iRow, 3) = IIf(strStatusCode = 0, "Response received", "No response")
    iRow = iRow + 1
  End With
Next
End Sub
Avatar of sirbounty
sirbounty
Flag of United States of America image

...and perhaps this would help get the list...run it from a command line

for /f "skip=3 delims=\\ " %a in ('net view') do echo %a >> c:\PCList.txt
Avatar of jaw0807
jaw0807
Flag of United States of America image

ASKER

When I run the VBS, wscript starts but nothing seems to happen.  I let it run for over an hour.  I then killed it in Task Manager and tried running it with Excel open and it did create an Excel file that time but all that was in there was all the computer names and a few IP addresses.  There were no "Response Received" or "No response".

Sorry for the delay in getting back to you, I was out sick the end of last week.  Also if it's easier the output file could be a comma delimited file.
Avatar of jaw0807
jaw0807
Flag of United States of America image

ASKER

OK, I got an error message with running it the second way (Excel open) afte a while.

Windows Script Host

Script: c:\pingtool2.vbs
Line: 29
Char: 1
Error: Object required: 'objExcel.ActiveWorkbook'
Code: 800A01A8
Source: Microsoft VBScript runtime error
ASKER CERTIFIED SOLUTION
Avatar of sirbounty
sirbounty
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Ryan_R
Ryan_R
Flag of Australia image

I don't know if you still want a program - but I made one like this a long time ago - it's on Softpedia.
http://www.softpedia.com/get/Windows-Widgets/Widget-Miscellaneous/PC-Ping.shtml
Avatar of Computer101
Computer101
Flag of United States of America image

Forced accept.

Computer101
EE Admin
Avatar of kwincel
kwincel

The .Cell(iRow, 3) line towards the end of the script is not working. i replaced with this and it's now working. Also, I recommend running the script from a server, which resolved the "IPs are showing for some, but not everything"

    If strStatusCode= 0 Then
      .Cells(iRow, 3) = "Yes"
    Else
      .Cells(iRow, 3) = "No"
    End if
Avatar of DavidLeal
DavidLeal

If any else want something like that, and like me dont have much experience with VBScripts, here are an util that works for me:

http://www.nirsoft.net/utils/multiple_ping_tool.html
Windows OS
Windows OS

This topic area includes legacy versions of Windows prior to Windows 2000: Windows 3/3.1, Windows 95 and Windows 98, plus any other Windows-related versions including Windows Mobile.

129K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo