中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-05 16:01
48,039 topics / 350,124 posts / today 2 new / 48,251 members
DOS批处理 & 脚本技术(批处理室) » 254 Threads (whew!!!) Batch file to ping any subnet (already tested)
Printable Version  1,357 / 6
Floor1 zw750516 Posted 2007-08-04 20:22
新手上路 Posts 7 Credits 16
//Using the 192.168.1. subnet as an example
ipconfig /all >ipconfig.txt
find "Default Gateway" ipconfig.txt >IP.txt
for /f "skip=2 tokens=13" %%a in (ip.txt) do echo %%a >ip.txt //Shows as 192.168.1.1 (gateway)
setlocal enabledelayedexpansion
for /f "tokens=*" %%d in (ip.TXT) do (
set str=%%d
echo !str:~0,-4! >ip.TXT) //Shows as 192.168.1. with a space after it
for /f "delims=" %%c in (ip.txt) do set a=%%c
if " " == "%a:~-1,1%" (set "a=%a:~0,-1%" ) //Remove the space through processing
set i=%a%
for /l %%p in (1,1,254) do @echo ping %i%%%p -n 1 >%%p.bat //Input the subnet variable
for /l %%p in (1,1,254) do @echo exit >>%%p.bat //Add the ending command
for /l %%p in (1,1,254) do start %%p.bat //254-thread command splicing
ping 1.1.1.1 -n 2 //Used for delay (I could only think of a simple one)
arp -a >arp.txt //Shows online IPs and MACs on the subnet. In current XP, if you don't ping them first, arp -a is useless. Everyone can try it, it will only show the gateway info.
del ipconfig.txt ip.txt
for /l %%p in (1,1,254) do del %%p.bat //Delete temporary files


[ Last edited by zw750516 on 2007-8-4 at 09:08 PM ]
Floor2 zw750516 Posted 2007-08-05 15:16
新手上路 Posts 7 Credits 16
Although it's not a very mature work, it's practical. How come nobody is discussing it or giving some pointers, sheesh!!!
Floor3 zw750516 Posted 2007-08-06 11:05
新手上路 Posts 7 Credits 16
The statements are too cumbersome, can any expert help revise it!!!
Floor4 429499381 Posted 2007-08-11 04:00
中级用户 Posts 202 Credits 452
Your batch processing really does need a lot of simplification!! I suspect your batch file simply can't get the result you want!!! At most it only gets your own gateway!!

Take a look at mine


@ipconfig /all | find "Default Gateway" >c:\1.txt

@for /f "tokens=1,2 delims=:" %%a in (c:\1.txt) do set ip=%%b

@echo %ip%

@set i=%ip:~1,9%

:loop

@set /a a+=1

@start /i /min ping -n 2 -w 500 %i%%a% >nul

@if "%a%"=="20" exit

@goto :loop

[ Last edited by 429499381 on 2007-8-11 at 04:35 AM ]
Floor5 zouzhxi Posted 2007-08-17 11:02
中级用户 Posts 177 Credits 430 From 广东深圳
RE 429499381:

Yours also only gets the gateway of the local subnet...

Hehe...
Floor6 qzwqzw Posted 2007-08-17 11:59
银牌会员 Posts 636 Credits 2,343
These are all not very mature works
You can refer to some earlier discussions
Floor7 zw750516 Posted 2007-08-29 17:09
新手上路 Posts 7 Credits 16
Originally posted by 429499381 at 2007-8-11 04:00 AM:
Your batch processing really does need a lot of simplification!! I suspect your batch file simply can't get the result you want!!! At most it only gets your own gateway!!

Take a look at mine


@ipconfig /all | f ...

My batch statements are cumbersome, but the result is definitely all online IP information on the subnet where the operating machine is located! Everyone can test it first before commenting.
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023