Re: ping all computer in lan...

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




"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)
)


.



Relevant Pages

  • Re: ping all computer in lan...
    ... You can use a DOS for loop, this will ping all computers in the 192.168.1.0 network: ... dim objPing, objRetStatus ... for each objRetStatus in objPing ...
    (microsoft.public.windows.server.scripting)
  • Re: ping all computer in lan...
    ... the 192.168.1.0 network (1 echo requests to send): ... WMI's ping class can be more granular: ... dim objPing, objRetStatus ... for each objRetStatus in objPing ...
    (microsoft.public.windows.server.scripting)
  • Re: I received an unknown Echo Request. What should I do, DENY or PERMIT?
    ... Why would I want anyone to "ping" me? ... if not to hack into my system? ... > several of these echo requests popping up each day. ... Microsoft is not the answer, ...
    (comp.security.firewalls)
  • Re: echo requests
    ... >>and whether I should Deny or Permit them. ... echo requests are ping or traceroute. ... To do ping or traceroute yourself, you need to permit ...
    (comp.security.firewalls)
  • Re: I received an unknown Echo Request. What should I do, DENY or PERMIT?
    ... Many applications will initiate a ping to see if you are "there" or "still ... >> several of these echo requests popping up each day. ...
    (comp.security.firewalls)