China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-05 16:53
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » 254 Threads (whew!!!) Batch file to ping any subnet (already tested) View 1,359 Replies 6
Original Poster Posted 2007-08-04 20:22 ·  中国 湖南 株洲 电信
新手上路
Credits 16
Posts 7
Joined 2007-08-03 22:29
19-year member
UID 94605
Gender Male
Status Offline
//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 ]
Floor 2 Posted 2007-08-05 15:16 ·  中国 湖南 株洲 电信
新手上路
Credits 16
Posts 7
Joined 2007-08-03 22:29
19-year member
UID 94605
Gender Male
Status Offline
Although it's not a very mature work, it's practical. How come nobody is discussing it or giving some pointers, sheesh!!!
Floor 3 Posted 2007-08-06 11:05 ·  中国 湖南 株洲 电信
新手上路
Credits 16
Posts 7
Joined 2007-08-03 22:29
19-year member
UID 94605
Gender Male
Status Offline
The statements are too cumbersome, can any expert help revise it!!!
Floor 4 Posted 2007-08-11 04:00 ·  中国 湖北 武汉 电信
中级用户
★★
Credits 452
Posts 202
Joined 2006-12-21 13:46
19-year member
UID 74161
Gender Female
Status Offline
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 ]
Floor 5 Posted 2007-08-17 11:02 ·  IANA 局域网IP(Private-Use)
中级用户
★★
蝴蝶之吻
Credits 430
Posts 177
Joined 2006-09-20 12:00
19-year member
UID 63170
From 广东深圳
Status Offline
RE 429499381:

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

Hehe...
Floor 6 Posted 2007-08-17 11:59 ·  中国 山西 运城 联通
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
These are all not very mature works
You can refer to some earlier discussions
Floor 7 Posted 2007-08-29 17:09 ·  中国 湖南 株洲 电信
新手上路
Credits 16
Posts 7
Joined 2007-08-03 22:29
19-year member
UID 94605
Gender Male
Status Offline
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.
Forum Jump: