Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Ping IP ranges

33 views
Skip to first unread message

Jack Wray

unread,
Aug 21, 2003, 3:05:03 PM8/21/03
to
Hello all,

Has anyone created a script that pings an IP range and dumps the alive
machines to a file??

Been trying to get one to work but no luck as of yet.

Thanks
Jack


Alex K. Angelopoulos

unread,
Aug 21, 2003, 3:58:30 PM8/21/03
to
Jack,

Post what you have at this point and people can suggest modifications.
Alternatively, go to the Google newsgroups archive and look up IsConnectible
in the microsoft.public.scripting.* hierarchy

http://groups.google.com/groups?as_ugroup=microsoft.public.scripting.*&as_q=IsConnectible

Jack Wray

unread,
Aug 21, 2003, 4:40:46 PM8/21/03
to
Alex,

what i'm looking for is the syntax for stepping through a range. Currently
i'm getting a list of machines from the browse list , then pinging then
however this is missing machines that aren't announcing themselves to the
browse list. So having a script check a range of ips would be better. I'm
new to scripting so i'm missing the formula to get this.. i know it's like
"do X , Do X +1 till X=254, just don't know how to write it.

Alex K. Angelopoulos" <aka-at-mvps-dot-org> wrote in message
news:e1B5Z6Ba...@TK2MSFTNGP12.phx.gbl...

Alex K. Angelopoulos

unread,
Aug 21, 2003, 5:20:03 PM8/21/03
to
Jack, first you want the VBScript docs if you don't have them; they have a
bunch of examples which can be very useful for this type of thing...
http://www.microsoft.com/downloads/details.aspx?FamilyID=01592c48-207d-4be1-8a76-1c4099d7bbb9

Here's a quick example of doing a loop to generate complete IP addresses for
a range.

ipBase = "192.168.2."
for i = 1 to 254
ip = ipbase & i
'wscript.echo ip
' do something with ip here, like calling IsConnectible
next

Jack Wray

unread,
Aug 21, 2003, 8:30:45 PM8/21/03
to
thanks Alex.. I will slap the code together and see how it goes and post it
for others or completely mess it up and ask for help :)

"Alex K. Angelopoulos" <aka-at-mvps-dot-org> wrote in message
news:%23x3d%23nCaD...@TK2MSFTNGP09.phx.gbl...

Michael Bouchard

unread,
Aug 26, 2003, 11:09:39 AM8/26/03
to
Here is an example of what we are using to ping a collection of IP's. For
this script, a file (ipaddress.txt) is required and must be in the same
folder as the script, but this should be easily edited as needed. It will
then output all ping results to a spreadsheet.
Watch out for line wraps.

Mike

'IP Ping.vbs
'Ping multiple computers taken from a list in a text file out put to an
Excel Spreadsheet
' Requirments: List of IP Addresses in a file called (See strFileName for
the required text file)
' One IP Address per line
' Excel is needed
' Script was written in Windows XP using Wscript 5.6
' No blank line at the end of the script
'***************************************************************************
***************
Option Explicit
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

Dim strFileName : strFileName = "IPAddress.txt"

Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject")
Dim oXLS : Set oXLS = WScript.CreateObject("Excel.Application")
Dim WshShell : Set WshShell = createobject("wscript.shell")

Dim i
Dim intIndex
Dim oFile
Dim png
Dim strComputerIP()
Dim strIpAddress
Dim strPing
Dim strReply
Dim strRet
Dim strCname

If Not Fso.FileExists(strFileName) then
strRet = Msgbox("The file, " & strFileName & " is not available" & vbCr _
& "The file must be located in the same folder as the script." & vbCR _
& "Please check for the file <<" & strFileName & ">> in the folder"
& vbCR _
& "<<" & Fso.GetParentFolderName(Wscript.ScriptFullName) & ">>")
Wscript.Quit

End if

Set oFile = Fso.OpenTextFile(strFileName, 1)

'Configure Excel while leaving the spreadsheet hidden

oXLS.WorkBooks.Add
oXLS.Columns(1).ColumnWidth = 20
oXLS.Columns(2).ColumnWidth = 30
oXLS.Columns(3).ColumnWidth = 40

'Set column headers
oXLS.Cells(1, 1).Value = "IP Address"
oXLS.Cells(1, 2).Value = "Computer Name"
oXLS.Cells(1, 3).Value = "Return"

'Format text (bold)
oXLS.Range("A1:C1").Select
oXLS.Selection.Font.Bold = True
oXLS.Selection.Interior.ColorIndex = 1
oXLS.Selection.Interior.Pattern = 1 'xlSolid
oXLS.Selection.Font.ColorIndex = 2
'Left Align text
oXLS.Columns("B:B").Select
oXLS.Selection.HorizontalAlignment = &hFFFFEFDD ' xlLeft


intIndex = 2
i = 0
Do Until oFile.AtEndOfStream
Redim Preserve strComputerIP(i)
strComputerIP(i) = oFile.ReadLine
'Ping Ip Addresses
set png = WshShell.exec("ping -a -n 1 " & strComputerIP(i))
do until png.status = 1 : wscript.sleep 10 : loop
strPing = png.stdout.readall

'NOTE: The string being looked for in the Instr is case sensitive.
'Do not change the case of any character which appears on the
'same line as a Case InStr. As this will result in a failure.
Select Case True
Case InStr(strPing, "Request timed out") > 1
strReply = "Request timed out"
strCname = lcase(getcName(strPing))
Case InStr(strPing, "could not find host") > 1
strReply = "Host not reachable"
strCname = lcase(getcName(strPing))
Case InStr(strPing, "Reply from") > 1
strReply = "Ping Succesful"
strCname = lcase(getcName(strPing))
End Select
If strCName = "" then
strCname = "N/A"
End If
Call Show(strComputerIP(i), strCName, strReply)
i = i + 1
Loop

'Make the spreadsheet visable
oXLS.Visible = TRUE


Function GetcName(ByVal reply)
Dim C, tempcName
C = Instr(reply,"[")
If C = 0 Then Exit Function
TempcName = mid(reply,12,C-12)
'Used to remove the FQDN from the computer name.
GetcName = replace(tempcName, ".ci.charlotte.nc.us", "",1)
End Function

Sub Show(strIP, strName, strValue)
oXLS.Cells(intIndex, 1).Value = strIP
oXLS.Cells(intIndex, 2).Value = strName
oXLS.Cells(intIndex, 3).Value = strValue
intIndex = intIndex + 1
oXLS.Cells(intIndex, 1).Select
End Sub


"Jack Wray" <jack...@comcast.net> wrote in message
news:%23Vc8ubB...@TK2MSFTNGP09.phx.gbl...

0 new messages