Hello? Is anyone out there? If so, ping me..

When you are looking for something, like a piece of hardware, and you don't know where to start looking, it is always useful to have a good set of tools.

For example, I wanted to find what IP address that a new UPS device was using. I could not locate it in the DHCP tables and figured it must have a static IP address. The administration tools could not access it via the USB cable, so I needed to brute force search for the IP address. What I would do for an IP scanner right then? Code one!

The script below is a command-line script that uses WMI to check the pingstatus of the system at each IP address. I grabbed parts from Windows IT Pro. So far, it will only increment the last octet of the IP address. Maybe if the need arises, I will modify the code to take a start and end range.

Update:
After reviewing Scott's enormous list of his favorite tools, I found this one which appears to have a great GUI.


' Ping Range Script (PingIP.vbs)
' By Eric Woodford (http://www.ericwoodford.com)
' Original Source from http://www.windowsitpro.com/Article/ArticleID/48449/48449.html

Option Explicit

Dim strHost, strEnd
Dim Start_IP, x, strIP

' Check that all arguments required have been passed.
If Wscript.Arguments.Count < 1 Then
Wscript.Echo "Arguments required. For example:"
Wscript.Echo "Ping a single IP address or hostname:"
Wscript.Echo vbtab& "cscript PingIP.vbs (hostname)"
Wscript.Echo vbtab& "cscript PingIP.vbs ipaddress" & vbcrlf
Wscript.Echo "Ping a range of IP addresses from ipaddress to ipaddress+count"
Wscript.Echo vbtab& "cscript vbping.vbs ipaddress count"
Wscript.Quit(0)
End If

strHost = Wscript.Arguments(0)
if wscript.arguments.count = 2 then
strEnd = wscript.arguments(1)
if not(isnumeric(strend)) then
wscript.echo "Count argument needs to be numeric (1-254)."
wscript.quit
end if
if cint(strend)>=254 or cint(strend)<=0 then
wscript.echo "Count argument needs to be numeric (1-254)."
wscript.quit
end if
strEnd=cint(strEnd)
end if
if strEnd <> "" then
'get last subnet of start
strIP = left(strHost,instrrev(strHost,"."))
Start_IP = right(strhost,len(strHost)- instrrev(strHost,"."))
if isnumeric(start_IP) then
start_ip=cint(start_ip)
else
wscript.echo "ERROR: To ping a range, you need to put in the starting IP address, not a hostname"
wscript.quit(0)
end if
if start_ip = 0 then start_ip = 1
wscript.echo start_ip + strEnd
if (Start_IP + strEnd) > 255 then
wscript.echo "range exceeds maximum for octet."
strEnd= strend - ((start_ip+strend)-255)
wscript.echo "converting max of range to :" & strEnd
end if
for x = start_IP to (start_ip + strEnd)
if Ping(strIP&x) = True then
Wscript.Echo "Host " & strIP&x & " contacted"
Else
Wscript.Echo "Host " & strIP&x & " could not be contacted"
end if
next
Else
if Ping(strHost) = True then
Wscript.Echo "Host " & strHost & " contacted"
Else
Wscript.Echo "Host " & strHost & " could not be contacted"
end if
End If

Function Ping(strHost)

dim objPing, objRetStatus

set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
("select * from Win32_PingStatus where address = '" & strHost & "'")

for each objRetStatus in objPing
if IsNull(objRetStatus.StatusCode) or objRetStatus.StatusCode<>0 then
Ping = False
'WScript.Echo "Status code is " & objRetStatus.StatusCode
else
Ping = True
'Wscript.Echo "Bytes = " & vbTab & objRetStatus.BufferSize
'Wscript.Echo "Time (ms) = " & vbTab & objRetStatus.ResponseTime
'Wscript.Echo "TTL (s) = " & vbTab & objRetStatus.ResponseTimeToLive
end if
next
End Function

Function Resolve(strHost)

dim objPing, objRetStatus

set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
("select * from Win32_ComputerSystem where address = '" & strHost & "'")

for each objRetStatus in objPing
if IsNull(objRetStatus.StatusCode) or objRetStatus.StatusCode<>0 then
Resolve = ""
'WScript.Echo "Status code is " & objRetStatus.StatusCode
else
Resolve = True
'Wscript.Echo "Bytes = " & vbTab & objRetStatus.BufferSize
'Wscript.Echo "Time (ms) = " & vbTab & objRetStatus.ResponseTime
'Wscript.Echo "TTL (s) = " & vbTab & objRetStatus.ResponseTimeToLive
end if
next
End Function

AttachmentSize
PingIP.zip1.21 KB

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <blockquote> <center> <hr> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options