Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Pinging script that prompts for address range.

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,1731
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Pinging script that prompts for address range.
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Pinging script that prompts for address range. - 12/20/2004 12:43:36 PM   
  ned4spd8874

 

Posts: 1
Score: 0
Joined: 12/20/2004
From: USA
Status: offline
I am very new to scripting and I am sure this is something very simple to do. I need a script that will as me for a starting address, an ending address and then simply ping those addresses and output the results to a file.

Any help would be appreciated!
 
 
Post #: 1
 
 Re: Pinging script that prompts for address range. - 12/21/2004 12:53:11 AM   
  mbouchard


Posts: 1856
Score: 14
Joined: 5/15/2003
From: USA
Status: offline
Here is a script that I use to ping a range of IP's from a text file. You could modify this to use a range of ip's instead.

      

(in reply to ned4spd8874)
 
 
Post #: 2
 
 Re: Pinging script that prompts for address range. - 1/28/2005 12:04:36 AM   
  Thierry

 

Posts: 1
Score: 0
Joined: 1/28/2005
From:
Status: offline
HI,

Could you inform how to minimize windows opened by the Ping method.

such as the
*** set png = WshShell.RUN("ping -a -n 1 " & strComputerIP(i)),6***

Thanks in advance!


quote:
Originally posted by mbouchard

Here is a script that I use to ping a range of IP's from a text file. You could modify this to use a range of ip's instead.

      


(in reply to ned4spd8874)
 
 
Post #: 3
 
 Re: Pinging script that prompts for address range. - 1/28/2005 1:08:28 AM   
  mbouchard


Posts: 1856
Score: 14
Joined: 5/15/2003
From: USA
Status: offline
Thierry,

I responded to your email but as some might be interested in this, here is code that uses .RUN instead of .EXEC, it creates a file using >ECHO and runs the cmd window minimized. I then read the file and set a variable which is then used to check for ping status. Right before the excel spreadsheet is displayed I delete the txt file created using >ECHO.


      

(in reply to ned4spd8874)
 
 
Post #: 4
 
 Re: Pinging script that prompts for address range. - 2/6/2005 1:52:00 AM   
  johnny_boy

 

Posts: 1
Score: 0
Joined: 2/6/2005
From:
Status: offline
Here's my script that prompts for start and end IP address, pings the range, performst and nbtstat -A on devices that reply and creates 4 text .log files of the results in C:\ with filenames that starts with Ping

'*******************************************************************************
'
' Ping IP Range v1.0
'
' (c) 2005 Jonathan Wallace
'
'*******************************************************************************


'*******************************************************************************
'
' Main Program
'
'*******************************************************************************


On Error Resume Next


'-------------------------------------------------------------------------------
' Declare Constants
'-------------------------------------------------------------------------------

Const FOR_WRITING = 2
Const LOG_FILE_PATH = "C:\"
Const ECHOES = 4


'-------------------------------------------------------------------------------
' Set Global Variable Values
'-------------------------------------------------------------------------------

strPingAllLogFilePath = LOG_FILE_PATH & "Ping All Output.log"
strPingReplyLogFilePath = LOG_FILE_PATH & "Ping Reply.log"
strPingNoReplyLogFilePath = LOG_FILE_PATH & "Ping No Reply.log"
strPingPartialLossLogFilePath = LOG_FILE_PATH & "Ping Partial Packet Loss.log"


'-------------------------------------------------------------------------------
' Get Start of Range IP address
'-------------------------------------------------------------------------------

strIPStart = " "
bValid = False
While (bValid = False) AND (strIPStart <> "")
strIPStart = InputBox("Enter Start of Range IP address:", "Ping IP Range")
'Remove leading and trailing spaces
strIPStart = Trim(strIPStart)
'Test that entry is a valid IP address
bValid = ValidIP(strIPStart)
If (bValid = False) AND (strIPStart <> "") Then MsgBox strIPStart & " is not a valid IP address", vbCritical, "Ping IP Range"
WEnd


'-------------------------------------------------------------------------------
' Get End of Range IP address
'-------------------------------------------------------------------------------

strIPEnd = " "
bValid = False
While (bValid = False) AND (strIPStart <> "") AND (strIPEnd <> "")
strIPEnd = InputBox("Start of Range: " & strIPStart & VBLF & VBLF & "Enter End of Range IP address:", "Ping IP Range", strIPStart)
'Remove leading and trailing spaces
strIPEnd = Trim(strIPEnd)
'Test that entry is a valid IP address
bValid = ValidIP(strIPEnd)
If (bValid = False) AND (strIPEnd <> "") Then
MsgBox strIPEnd & " is not a valid IP address", vbCritical, "Ping IP Range"
ElseIf (iIPEnd < iIPStart) AND (strIPEnd <> "") Then
MsgBox strIPEnd & " is before the Start of Range: " & strIPStart, vbCritical, "Ping IP Range"
bValid = False
End If
WEnd


'-------------------------------------------------------------------------------
' Get Number of Ping Echoes to Send
'-------------------------------------------------------------------------------

strEchoes = " "
bValid = False
While (bValid = False) AND (strIPStart <> "") AND (strIPEnd <> "") AND (strEchoes <> "")
strEchoes = InputBox("Enter Number of Ping Echoes to Send:", "Ping IP Range", ECHOES)
'Remove leading and trailing spaces
strEchoes = Trim(strEchoes)
'Test that entry is a Number
bValid = ValidNumber(strEchoes)
If (bValid = False) AND (strEchoes <> "") Then MsgBox strEchoes & " is not a valid number", vbCritical, "Ping IP Range"
WEnd


'-------------------------------------------------------------------------------
' Ping Range
'-------------------------------------------------------------------------------

'If User did not Cancel
If (strIPStart <> "") AND (strIPEnd <> "") AND (strEchoes <> "") Then
Set objShell = CreateObject("WScript.Shell")

Set objFSO = CreateObject("Scripting.FileSystemObject")

'Create Log Files
Set objPingAllLogFile = objFSO.CreateTextFile(strPingAllLogFilePath, False)
Set objPingReplyLogFile = objFSO.CreateTextFile(strPingReplyLogFilePath, False)
Set objPingNoReplyLogFile = objFSO.CreateTextFile(strPingNoReplyLogFilePath, False)
Set objPingPartialLossLogFile = objFSO.CreateTextFile(strPingPartialLossLogFilePath, False)

'Open Log Files for OverWriting
Set objPingAllLogFile = objFSO.OpenTextFile(strPingAllLogFilePath, FOR_WRITING)
Set objPingReplyLogFile = objFSO.OpenTextFile(strPingReplyLogFilePath, FOR_WRITING)
Set objPingNoReplyLogFile = objFSO.OpenTextFile(strPingNoReplyLogFilePath, FOR_WRITING)
Set objPingPartialLossLogFile = objFSO.OpenTextFile(strPingPartialLossLogFilePath, FOR_WRITING)

'Write Start of Log Files
objPingAllLogFile.WriteLine Date & " " & Time & vbTab & "Ping IP Range: " & strIPStart & " to " & strIPEnd & vbTab & "All Output Log"

(in reply to ned4spd8874)
 
 
Post #: 5
 
 Re: Pinging script that prompts for address range. - 2/6/2005 5:00:21 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
Wow, that looked awfully complicated :D

(in reply to ned4spd8874)
 
 
Post #: 6
 
 RE: Re: Pinging script that prompts for address range. - 8/14/2007 8:00:41 AM   
  trsix

 

Posts: 18
Score: 0
Joined: 12/6/2006
From: Vancouver BC
Status: offline
quote:

ORIGINAL: Thierry

HI,

Could you inform how to minimize windows opened by the Ping method.

such as the
*** set png = WshShell.RUN("ping -a -n 1 " & strComputerIP(i)),6***

Thanks in advance!



Hi I know that this is long overdue, but i thought i'd post my code here.  I didnt like the way that windows kept on getting openend up and such so i used wmi to do the ping.
Tell me what you think.

      

(in reply to Thierry)
 
 
Post #: 7
 
 RE: Re: Pinging script that prompts for address range. - 8/14/2007 10:55:12 PM   
  Rischip


Posts: 468
Score: 2
Joined: 3/26/2007
Status: offline
Just keep in mind that the last octet 0-255 does not define an entire subnet.

The code in this post will ping an entire subnet. It requires an IP address on the subnet (any one of them) and the subnet mask.

http://www.visualbasicscript.com/m_48274/mpage_1/key_/tm.htm#48297

_____________________________

Rischip
Author of - The Grim Linker

(in reply to trsix)
 
 
Post #: 8
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Pinging script that prompts for address range. Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts