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-07-06 16:01
中国DOS联盟论坛 » DOS学习入门 & 精彩文章 (教学室) » Problems with PING View 2,166 Replies 19
Original Poster Posted 2007-03-08 11:14 ·  中国 山东 威海 联通
初级用户
Credits 36
Posts 13
Joined 2007-03-08 10:39
19-year member
UID 81082
Gender Male
Status Offline
Make a batch script to test whether the connection to a certain IP address is normal. Below is what I wrote, very crude haha.

ping 17.0.11.1 > a.txt
type a.txt | find "ms" && echo ----Connection is normal----

Is there a way to determine connectivity without generating a .txt file?
Thanks
Floor 2 Posted 2007-03-08 12:08 ·  中国 山东 威海 联通
初级用户
Credits 36
Posts 13
Joined 2007-03-08 10:39
19-year member
UID 81082
Gender Male
Status Offline
Too late, everyone is asleep?
Hehe
Floor 3 Posted 2007-03-09 03:42 ·  中国 青海 海东 中移铁通
新手上路
Credits 4
Posts 2
Joined 2006-09-03 23:49
19-year member
UID 61789
Status Offline
ping 17.0.11.1
pause
Floor 4 Posted 2007-03-09 05:22 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
ping 127.0.0.1|find "ms" >nul&&echo OK
Floor 5 Posted 2007-03-09 05:55 ·  中国 广东 珠海 电信
初级用户
Credits 57
Posts 29
Joined 2006-09-27 02:04
19-year member
UID 63754
Status Offline
Floor 6 Posted 2007-03-09 06:04 ·  中国 甘肃 张掖 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
Originally posted by lxmxn at 2007-3-9 05:22:
ping 127.0.0.1|find "ms" >nul&&echo OK

Why is it written so complicated?

ping -n 1 127.1>nul 2>nul &&(echo ok)
Floor 7 Posted 2007-03-09 08:30 ·  中国 上海 青浦区 电信
初级用户
发粪涂墙
Credits 30
Posts 16
Joined 2007-03-08 07:07
19-year member
UID 81065
Gender Male
From 上海
Status Offline
Still not quite clear!
Floor 8 Posted 2007-03-10 08:36 ·  中国 山东 威海 联通
初级用户
Credits 36
Posts 13
Joined 2007-03-08 10:39
19-year member
UID 81082
Gender Male
Status Offline
Often see this thing, also checked on the net. Also checked in the XP built-in help. Still didn't understand. Which boss can give an explanation? Thanks
Floor 9 Posted 2007-03-11 10:35 ·  中国 江苏 南京 电信
初级用户
Credits 76
Posts 39
Joined 2007-03-09 06:54
19-year member
UID 81169
Gender Male
Status Offline
It seems that ping -n 1 127.1>nul&&echo ok is okay. What about 2>nul? Let me explain.

In the command line, 2>nul is used to redirect the standard error output (stderr) to the null device, which means to suppress the error messages. For example, if there is an error message that would normally be displayed, using 2>nul will make it not show up.
狐狸喜欢狡猾。。
Floor 10 Posted 2007-03-11 11:02 ·  中国 四川 成都 教育网
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
Search by yourself, search in the forum

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Floor 11 Posted 2007-03-11 11:07 ·  中国 江苏 南京 电信
初级用户
Credits 76
Posts 39
Joined 2007-03-09 06:54
19-year member
UID 81169
Gender Male
Status Offline
Originally posted by marryli at 2007-3-7 22:14:
Make a batch script
Test if the connection to a certain IP address is normal
The following is what I wrote, very simple ha

ping 17.0.11.1 > a.txt
type a.txt | find "ms" && echo ----Connection normal----



There is ...

set count=10
:again
set b=false
ping 17.0.11.1|find "ms"&&set b=ok&&echo ----Connection normal------&&exit
if %b%==false echo -----Can't connect------
set count=count-1 ::Feels a bit wrong,....
if count==0 exit
goto again
狐狸喜欢狡猾。。
Floor 12 Posted 2007-03-11 11:43 ·  中国 江苏 南京 电信
初级用户
Credits 76
Posts 39
Joined 2007-03-09 06:54
19-year member
UID 81169
Gender Male
Status Offline
>It's redirection. The output of the command is displayed in cmd by default. Using > won't display it.
>nul releases the output
狐狸喜欢狡猾。。
Floor 13 Posted 2007-03-12 00:43 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
Originally posted by hxmupdata at 2007-3-10 22:07:
set count=10
:again
set b=false
ping 17.0.11.1|find "ms"&&set b=ok&&echo ----连接正常------&&exit
if %b%==false echo -----连接不到------
set count=count-1 ::感觉这有点不对,....
if count==0 exit
goto again

To perform arithmetic operations with set, you should add the "/a" parameter. It should be "set /a count=count-1"

[ Last edited by lxmxn on 2007-3-15 at 11:29 AM ]
Floor 14 Posted 2007-03-12 06:20 ·  中国 江苏 南京 电信
初级用户
Credits 76
Posts 39
Joined 2007-03-09 06:54
19-year member
UID 81169
Gender Male
Status Offline
Originally posted by lxmxn at 2007-3-11 11:43:

You should add the parameter "/a" when using set for arithmetic operations, "set /a count==count-1"

Oh, I see. I'm just learning. I usually program in other languages...
狐狸喜欢狡猾。。
Floor 15 Posted 2007-03-12 06:26 ·  中国 江苏 南京 电信
初级用户
Credits 76
Posts 39
Joined 2007-03-09 06:54
19-year member
UID 81169
Gender Male
Status Offline
Ask a question: If you don't add "/a count=count-1", what will the value of count be? Why...
I don't know if my own understanding is correct
狐狸喜欢狡猾。。
Forum Jump: