Re: ping all computer in lan...
- From: "Pegasus \(MVP\)" <I.can@xxxxxxxxxx>
- Date: Mon, 7 Apr 2008 19:39:25 +0200
"Shay Levi" <no@xxxxxxxx> wrote in message
news:8766a94426ca98ca66f329679e9e@xxxxxxxxxxxxxxxxxxxxx
Hi
You can use a DOS for loop, this will ping all computers (1-255) in the
192.168.1.0 network (1 echo requests to send):
For /L %X In (1,1,255) Do ping -n 1 192.168.1.%X
WMI's ping class can be more granular:
subnet = "192.168.1."
for i=1 to 255
strHost = subnet &i
if Ping(strHost) = True then
Wscript.Echo "Host " & strHost & " is on-line"
Else
Wscript.Echo "Host " & strHost & " is off-line"
end if
next
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
end if
next
End Function
You can make your batch file just as granular:
@echo off
For /L %%x In (1,1,255) Do
ping -n 1 192.168.1.%%x | find /i "bytes=" > nul
if ErrorLevel 1 (echo 192.168.1.%%x is off-line) else (echo 192.168.1.%%x
is on-line)
)
.
- Follow-Ups:
- Re: ping all computer in lan...
- From: Shay Levi
- Re: ping all computer in lan...
- References:
- ping all computer in lan...
- From: sal21
- Re: ping all computer in lan...
- From: Shay Levi
- ping all computer in lan...
- Prev by Date: Re: Lastlogontimestamp
- Next by Date: Re: ping all computer in lan...
- Previous by thread: Re: ping all computer in lan...
- Next by thread: Re: ping all computer in lan...
- Index(es):
Relevant Pages
|