标题: 新人学dos.学不会bat判断
[打印本页]
作者: snowbbbb
时间: 2008-3-12 10:04
标题: 新人学dos.学不会bat判断
ping 192.168.0.1 >1.txt
type 1.txt | find "time<1ms" & set a=time<1ms
if "%a%"=="%a%" goto end
if not "%a%"=="%a%" goto noping
这样提问可能会好一点, 能否有人告知一下 这个地方该怎么写+
或者是 我想做一个检测 如果ping 192.168.1通的话 跳到一个 如果不通的话 跳到另一个
[
Last edited by snowbbbb on 2008-3-12 at 08:48 PM ]
作者: snowbbbb
时间: 2008-3-12 11:04
另外想问一下,
:noping
echo.
pause & exit
:end
echo.
pause & exit有必要么?
:这个标签 标到什么时候结束呢?
作者: abcd
时间: 2008-3-12 11:07
find "%a%" 1.txt>nul 2>nul&&goto end
类似这样。
说实话,上面的P,可以进一步优化
作者: snowbbbb
时间: 2008-3-12 11:48
abcd能否给出优化后的代码?
作者: abcd
时间: 2008-3-12 12:06
Quote: |
arp -d
if exist ipconfig.txt del ipconfig.txt
ipconfig /all >ipconfig.txt
if exist phyaddr.txt del phyaddr.txt
find "Physical Address" ipconfig.txt >phyaddr.txt
for /f "skip=2 tokens=12" %%M in (phyaddr.txt) do set Mac=%%M
if exist IPAddr.txt del IPaddr.txt
find "IP Address" ipconfig.txt >IPAddr.txt
for /f "skip=2 tokens=15" %%I in (IPAddr.txt) do set IP=%%I
arp -s %IP% %Mac%
del ipaddr.txt
del ipconfig.txt
del phyaddr.txt
arp -s 192.168.0.1 00-02-b3-3a-2f-c7 |
|
可以这样。
set flag=
for /f "tokens=2 delims=:" %%i in ('ipconfig /all^|find /i "address"') do (
if not defined flag set mac=%%i&set flag=flag
set ip=%%i
)
arp -d
arp -s %ip:~1% %mac:~1%
作者: bat-zw
时间: 2008-3-12 16:46
呵呵,你应该是个网吧的网管这段(noping开始)应是来源于网上,我看过类似的,好了不多说了,为了共同提高的目的,我来解决你前面的问题,呵呵,代码如下:
findstr /c:"%a%" 1.txt
if errorlevel 0 goto :eof\:eof 表示结束整个P处理
findstr /c:"%b%" 1.txt
if errorlevel 0 goto noping
但不知道当两个字符串都没找到你要怎么处理,给个建议你吧:
findstr /c:"%a%" 1.txt
if errorlevel 0 goto :eof
findstr /c:"%b%" 1.txt
if errorlevel 0 goto noping
:set
cls&set /p a=没有找到任何字符串,是否继续程序运行:(1.继续 2.结束)
if "%a%"="1" goto wrong
if "%a%"="2" goto :eof
:wrong
cls&echo 输入错误,请返回正确输入!&ping/n 3 127.1 >nul&goto set
[
Last edited by zw19750516 on 2008-3-12 at 04:58 PM ]
作者: snowbbbb
时间: 2008-3-12 18:28
zw19750516 find和findstr有什么区别?
双绑的确是来自于网上 要不也不会出现使用for命令而我不会用的情况了,
if errorlevel 0 这种模式是怎么讲的呢 偶在cmd if /?看不到这个帮助。
能否讲解一下
作者: snowbbbb
时间: 2008-3-12 18:43
@echo off & title 网关修复程序
mode con cols=20 lines=10
color 9f
echo.
echo ====================
echo ....检测中...
echo ====================
echo.
ping 192.168.0.1 >1.txt
type 1.txt | find "time<1ms" & set a=time<1ms
if "%a%"=="%a%" goto end
if not "%a%"=="%a%" goto noping
:noping
cls
color 8b
set flag=
for /f "tokens=2 delims=:" %%i in ('ipconfig /all^|find /i "address"') do (
if not defined flag set mac=%%i&set flag=flag
set ip=%%i
)
arp -d
arp -s %ip:~1% %mac:~1%
arp -s 192.168.0.1 00-02-b3-3a-2f-c7
cls
echo.
echo ====================
echo 修复完毕,如果打不
echo 开网页, 请联系网管.
echo ====================
echo.
:end
cls
color 3f
echo.
echo ====================
echo 网络畅通,如果忘记
echo 刷卡, 请呼叫网管.
echo ====================
echo.
pause & exit
.
还是迷惑中。。。。。。教学的贴都用了太多非所教的命令 比如教if 会用for命令来教。。。。
[
Last edited by snowbbbb on 2008-3-12 at 07:36 PM ]
作者: snowbbbb
时间: 2008-3-12 19:49
type 1.txt | find "time<1ms" && if "%a%"=="Minimum" goto end ||if not "%a%"=="Minimum" goto noping
这句话是不是可以这样理解呢
如果在1.txt里找到了time<1ms那么执行下一句gotoend 下边的不再执行
如果在1.txt里没找到time<1ms那么招待后边的if not这一句?