Re: Batch file for Ping?
- From: "Linn Kubler" <lkubler@xxxxxxxxxxxxxxxxxx>
- Date: Thu, 21 Sep 2006 08:21:25 -0500
Thanks Miguel I'll give it a look-see, I've also heard of another one called
Angry IPScanner.
Linn
"miguel-lopes" <milopes@xxxxxxxxxxx> wrote in message
news:uhskgPM3GHA.988@xxxxxxxxxxxxxxxxxxxxxxx
There is a very good program that you can use and exports the information
to
a txt file called IPSCAN and it is very small and free!
Hope that helps
"Richard Mueller" <rlmueller-NOSPAM@xxxxxxxxxxxxxxxxxxxx> escreveu na
mensagem news:eEfHUtA3GHA.476@xxxxxxxxxxxxxxxxxxxxxxx
Hi,computers
If you want to know which machines have which IP address, the VBScript
program below produces a comma delimited file with NetBIOS name of the
computer and IP Address. It uses ADO to retrieve the names of all
joined to the domain. Run at a command prompt and redirect the output to
a
text file. For example, if the program is in a file called
PingComputers.vbs, this command redirects the output to a file called
report.txt:
cscript //nologo PingComputers.vbs > report.txt
The VBScript program (watch for line wrapping):
======
Option Explicit
Dim strIPAddress, objShell, objFSO, strTemp, strTempFile
Dim strComputer, adoConnection, adoCommand, adoRecordset
Dim objRootDSE, strFiler, strAttributes, strQuery
Dim strDNSDomain
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Wscript.Shell")
' Specify temporary file to save ping results.
strTemp = objShell.ExpandEnvironmentStrings("%TEMP%")
strTempFile = strTemp & "\RunResult.tmp"
' Determine DNS domain name from RootDSE object.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
' Use ADO to search Active Directory for all computers.
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open = "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection
' Comma delimited list of attributes values to retrieve.
strAttributes = "sAMAccountName,distinguishedName"
' Construct the LDAP syntax query.
strQuery = "<LDAP://" & strDNSDomain _
& ">;(ObjectCategory=computer);" & strAttributes & ";subtree"
' Execute the query.
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False
Set adoRecordset = adoCommand.Execute
' Enumerate the recordset.
Do Until adoRecordset.EOF
' Retrieve the NetBIOS name of the computer.
strComputer = adoRecordset.Fields("sAMAccountName")
' Remove trailing "$".
strComputer = Left(strComputer, Len(strComputer) - 1)
' Ping the computer for the IP Address.
strIPAddress = PingMachine(strComputer, 1, 750)
' Output computer NetBIOS name and IP Address.
Wscript.Echo strComputer & "," & strIPAddress
adoRecordset.MoveNext
Loop
' Clean up.
adoRecordset.Close
adoConnection.Close
Function PingMachine(strHost, intPings, intTO)
' Returns IP Address if strHost can be pinged.
' Based on a program by Alex Angelopoulos and Torgeir Bakken.
' Variables objFSO, objShell, and strTempFile have global scope
' and must be declared in the main program.
Dim objFile, strResults, intIndex1, intIndex2
Const OpenAsDefault = -2
Const FailIfNotExist = 0
Const ForReading = 1
If (intPings = "") Then
intPings = 2
End If
If (intTO = "") Then
intTO = 750
End If
' Ping the machine and pipe results to temporary file.
objShell.Run "%comspec% /c ping -n " & intPings & " -w " _
& intTO & " " & strHost & ">" & strTempFile, 0, True
' Read the file.
Set objFile = objFSO.OpenTextFile(strTempFile, ForReading, _
FailIfNotExist, OpenAsDefault)
strResults = objFile.ReadAll
objFile.Close
' Search for IP Address in square brackets.
intIndex1 = InStr(strResults, "[")
intIndex2 = InStr(intIndex1 + 1, strResults, "]")
Select Case InStr(strResults, "TTL=")
Case 0
' No response.
PingMachine = "<not found>"
Case Else
' Computer responded to ping, parse IP Address.
If (intIndex1 > 0) And (intIndex2 > intIndex1) Then
PingMachine = Mid(strResults, intIndex1 + 1, _
intIndex2 - intIndex1 - 1)
Else
PingMachine = "<unknown>"
End If
End Select
End Function
--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
.
- References:
- Batch file for Ping?
- From: Linn Kubler
- Re: Batch file for Ping?
- From: Richard Mueller
- Re: Batch file for Ping?
- From: miguel-lopes
- Batch file for Ping?
- Prev by Date: Re: Batch file for Ping?
- Next by Date: Re: List Group membership
- Previous by thread: Re: Batch file for Ping?
- Next by thread: Re: Batch file for Ping?
- Index(es):
Relevant Pages
|