Find a tool to ping a list of 3000 hostnames  and report which one is not pingable on the network.

nav2567
nav2567 used Ask the Experts™
on
Hello Experts,

I have just used a Microsoft DSQUERY tool to generate a list of 3000 computers which are inactive for more than 16 weeks.  The list is in .TXT format.

Is there a way or tool I can use to use the list (a txt file) and ping each computer and see if they are actually live?

This is probably a tough one.  Just want to see if anyone knows.

Thanks.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
On Error Resume Next
Const ForAppending = 8
Const ForReading = 1
Dim strShutdown
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set oFS = CreateObject("Scripting.FileSystemObject")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
Set oTS = oFS.OpenTextFile("C:\script\computer.txt", ForReading)
Set objTextFile = objFSO.OpenTextFile ("c:\script\Result.txt", ForAppending, True)
Do Until oTS.AtEndOfStream
strCompname = oTS.ReadLine
strPingStatus = PingStatus(strCompname)
If strPingStatus = "Success" Then

objTextFile.writeline "pinging Machine name -" & strCompname & ": " & strPingStatus

Else

    objTextFile.writeline "Failure pinging Machine name -" & strCompname & ": " & strPingStatus
End If
Loop
Wscript.Echo "Script has run Succesfully. Please see C:\Script\Result.txt file for results "


oTS.Close
objTextFile.close

Function PingStatus(strCompname)

    On Error Resume Next
   
    Set objWMIService = GetObject("winmgmts:" _
      & "{impersonationLevel=impersonate}!\\" & strCompname & "\root\cimv2")
    Set colPings = objWMIService.ExecQuery _
      ("SELECT * FROM Win32_PingStatus WHERE Address = '" & strCompname & "'")
    For Each objPing in colPings
        Select Case objPing.StatusCode
            Case 0 PingStatus = "Success"
            Case 11001 PingStatus = "Status code 11001 - Buffer Too Small"
            Case 11002 PingStatus = "Status code 11002 - Destination Net Unreachable"
            Case 11003 PingStatus = "Status code 11003 - Destination Host Unreachable"
            Case 11004 PingStatus = _
              "Status code 11004 - Destination Protocol Unreachable"
            Case 11005 PingStatus = "Status code 11005 - Destination Port Unreachable"
            Case 11006 PingStatus = "Status code 11006 - No Resources"
            Case 11007 PingStatus = "Status code 11007 - Bad Option"
            Case 11008 PingStatus = "Status code 11008 - Hardware Error"
            Case 11009 PingStatus = "Status code 11009 - Packet Too Big"
            Case 11010 PingStatus = "Status code 11010 - Request Timed Out"
            Case 11011 PingStatus = "Status code 11011 - Bad Request"
            Case 11012 PingStatus = "Status code 11012 - Bad Route"
            Case 11013 PingStatus = "Status code 11013 - TimeToLive Expired Transit"
            Case 11014 PingStatus = _
              "Status code 11014 - TimeToLive Expired Reassembly"
            Case 11015 PingStatus = "Status code 11015 - Parameter Problem"
            Case 11016 PingStatus = "Status code 11016 - Source Quench"
            Case 11017 PingStatus = "Status code 11017 - Option Too Big"
            Case 11018 PingStatus = "Status code 11018 - Bad Destination"
            Case 11032 PingStatus = "Status code 11032 - Negotiating IPSEC"
            Case 11050 PingStatus = "Status code 11050 - General Failure"
            Case Else PingStatus = "Status code " & objPing.StatusCode & _
               " - Unable to determine cause of failure."
        End Select
    Next

End Function
Please save the above script as .vbs script...
this will take input of machine names  from file C:\script\computer.txt
and put the result of ping in C:\script\Result.txt file.
Hi;

This program can be useful for you. http://ping-monitor.com/ This program is free for 5 hosts. If you use more than 5 hosts, you will have to pay $ 49.00.

Also there is some freeware software for this job. One of them is in this web: http://ping-plus-for-xp-and-vista.3dsnmp.qarchive.org/
yo_beeDirector of Information Technology
Commented:
Just a little tidbit:
If your machine has firewall options enabled on the machine/machines your ping request might generate a False Positive making it look like that machine/machines are not on or disconnected from the network.

If your run  ARP -a <ip-address>  this is a better method to validate your machine availability.


You can also make your script a bit more dynamic by leveraging VBS ADSI connection rather than generating a text file that needs to be read.

One I compiled over the years is this one below.  I know I said that PING is not a good method to see if your machine is available, but I know I do not have Windows Firewall Settings enabled on my network.

The code portion that you would be interested in is line 1 - 57 (AD Bind)  and 151 - 166 (Ping)
on error resume next
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adUseClient = 3
Const adStateOpen = 1

Const ADS_PROPERTY_CLEAR = 1
Const ADS_PROPERTY_UPDATE = 2
Const ADS_PROPERTY_APPEND = 3
Const ADS_PROPERTY_DELETE = 4
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")

Dim StrComputerName, StrUser
Dim StrMemory 'as interger
Dim objConn 'ADO Connection object
Dim objRS 'ADO Recordset object

'************************************************************************************
'Connecting to Active Directory														*
'************************************************************************************
objConnection.Provider = "ADSDSOObject"
objConnection.Open "" 
If objConnection.State = adStateOpen Then
'WScript.Echo "Authentication Successful!"
Else
'WScript.Echo "Authentication Failed."

WScript.Quit(1)
End If

'Get the Root DSE from a random DC
Set objRootDSE = GetObject("LDAP://RootDSE")

'Connect to the schema container on a random DC
strDNSDomain = objRootDSE.Get("defaultNamingContext")
Set StrDC = GetObject("LDAP://" & StrDNSDomain)
StrServices = Ucase(StrDC.DC)
wscript.echo StrServices
wscript.echo "Server Name,IP-Address,Make,Model,Serial Number,Memory,# of Cores,Cpu Speed,Architecture,,Chip Type" 
Set objRS = objConnection.Execute("<LDAP://" & strDNSDomain & ">;(&(objectCategory=computer)(objectClass=user));Name,ADsPath,operatingSystem;SubTree")
While Not objRS.EOF
strAlt = objRS.Fields.Item("operatingSystem").Value
strName = objRS.Fields.Item("Name").Value
strADs = objRS.Fields.Item("ADsPath").Value


'************************************************************************************
'Data Collection:  This section compares the the OS attribute and if Server is part *
'of the string it will continue to collect the servers data via WMI connections.     *
'This can be modified to meet your needs. 																	*
'************************************************************************************

If instr(strAlt,"Server") then
	blnping = PingHost  
If blnping = true then

'************************************************************************************
'Computers Phyiscal Memory
'************************************************************************************
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" _
    & strName & "\root\cimv2")
Set colSettings = objWMIService.ExecQuery _
    ("Select * from Win32_ComputerSystem")
For Each objComputer in colSettings 
   Strobj1 = objComputer.Name 
   strobj2 = (objComputer.TotalPhysicalMemory)/1024/1024/1024 
   strobj3 = objComputer.NumberOfProcessors
   Strobj11 = objComputer.Manufacturer
   StrObj12 = objcomputer.Model
      
Next

'************************************************************************************
'Computer Processor
'************************************************************************************
Set objWMIService = GetObject(_
    "winmgmts:\\" & strName & "\root\cimv2")
Set colItems = objWMIService.ExecQuery(_
    "Select * from Win32_Processor")
For Each objItem in colItems
   strobj4 = objItem.MaxClockSpeed
   Strobj8 = objItem.Caption
   Strobj9 = objItem.Name
   StrObj10 = objItem.AddressWidth	
            
Next

'************************************************************************************
'Computer Disk Space
'************************************************************************************
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" _
    & strname & "\root\cimv2")
Set colDisks = objWMIService.ExecQuery _
    ("Select * from Win32_LogicalDisk Where DriveType = 3")
For Each objDisk in colDisks
    
strobj5 = objDisk.DeviceID
    strobj6 = (objDisk.Size)/1024/1024/1024
    Strobj7 = (objDisk.FreeSpace)/1024/1024/1024
stroutput = Stroutput & "," & Strobj5 & "," & strobj6 & "," & Strobj7 

Next
'************************************************************************************
'Computer Bios
'************************************************************************************
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" _
    & strname & "\root\cimv2")
Set colBios = objWMIService.ExecQuery _
    ("Select * from Win32_Bios")
For Each objBios in colBios
    StrObj13 = objBios.SerialNumber
Next

'************************************************************************************
'Computer Network Details
'************************************************************************************
Dim k
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" _
    & strname & "\root\cimv2")
Set colNetwork = objWMIService.ExecQuery _
    ("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = 'True'")
For Each ObjNetwork in ColNetwork
    If Not IsNull(ObjNetwork.IPAddress) Then 
        For i=LBound(ObjNetwork.IPAddress) to UBound(ObjNetwork.IPAddress)
                StrObj14 = StrObj14 & " ; " & ObjNetwork.IPAddress(i)
        Next
    End If

next

wscript.echo strobj1 & "," & StrObj14 & "," & Strobj11 & "," & Strobj12 & "," & Strobj13 & "," & strobj2 & "," & strobj3 & "," & strobj4 & "," & StrObj10 & "," & StrObj8 & "," & StrObj9 & ","  & stroutput
'************************************************************************************
StrObj14 = ""
stroutput = ""
	End if
End IF								


objRS.MoveNext
			 Wend
	set objRS = Nothing
	objConnection.Close



'********************************************
'Pings the server to see if it's available  *
'******************************************** 

Function PingHost

Set objShell = CreateObject("WScript.Shell")
Set objExec = objShell.Exec("ping -n 2 -w 1000 " & strName)
strPingResults = LCase(objExec.StdOut.ReadAll)
If InStr(strPingResults, "reply from") Then
  PingHost = True
Else
	PingHost = False
End If

End Function

Open in new window

Author

Commented:
Thanks everyone ; )

Anuroopsundd, as you are the first one to reply, I am trying your script first.  I am testing against five pingable computers and put their names in the computer.txt.  However, I am seeing "Failure pinging Machine name -server...." in the result.txt file.

Author

Commented:
thanks.

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