NND,用了一上午,水平太菜了
@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%i in (WKT.txt)do (set ipaddr= %%i
for /f "delims=" %%m in ('ping -n 1 !ipaddr!^|find "TTL" ^>ping.txt ^&^& echo ping !
ipaddr! 1 ^|^| echo ping !ipaddr! 0')do (
set str_ping=!date!!time! %%m)
echo !str_ping!
)
【新】
@echo off
setlocal enabledelayedexpansion
for /f "tokens=1,2,4 delims= " %%i in (WKT.txt)do (set station= %%i
set contractor=%%j
set ipaddr=%%k
for /f "delims=" %%m in ('ping -n 1 !ipaddr!^|find "TTL" ^&^& echo ping !ipaddr! 1 ^|^| echo ping !ipaddr! 0')do (
set str_ping=!date!!time! !station!-!contractor!
set str_ping=!str_ping! %%m
echo !str_ping!>>ping.txt)
)
pause
【update】@2014-11-16
@echo off
set /p filename=please input the current contractor and station(e.g.816B-WKT):
echo your input is:%filename%
echo now the ping tesing is in progress,please wait..........................
setlocal enabledelayedexpansion
for /f "tokens=1,2,3,4 delims= " %%i in (gateway.txt)do (set station= %%i
set contractor=%%j
set description=%%k
set ipaddr=%%l
for /f "delims=" %%m in ('ping -n 1 !ipaddr!^|find "TTL" ^&^& echo !ipaddr! 1 ^|^| echo ping !ipaddr! 0')do (
set str_ping=!date!!time! !station!-!contractor!-!description! %%m
echo !str_ping!>>!filename!.txt)
)
echo.
echo ping testing is completed,please check the result
echo.
pause
【update】2014-11-17
@echo off
:restart
set /p filename=please input the current contractor and station(e.g.816B-WKT):
echo your input is:%filename% (Y/N?)
set /p selection=
if %selection%==Y goto continue
if %selection%==N goto restart
:continue
echo now the ping tesing is in progress,please wait..........................
setlocal enabledelayedexpansion
for /f "tokens=1,2,3,4 delims= " %%i in (gateway.txt)do (set station= %%i
set contractor=%%j
set description=%%k
set ipaddr=%%l
for /f "delims=" %%m in ('ping -n 4 !ipaddr!^|find "TTL" ^&^& echo ping !ipaddr! 1 ^|^| echo ping !ipaddr! 0')do (
set str_ping=!date!!time! !station!-!contractor!-!description! %%m
echo !str_ping!>>!filename!.txt)
)
echo.
echo ping testing is completed,please check the result in current directory with filename !filename!.txt
echo.
pause
PING交换机网关地址批处理
——————————————————————————————————
@echo off
echo change ip address (Y/N?)
set /p selection=
if %selection%==Y goto ipdizhi
if %selection%==N goto restart
:ipdizhi
echo please input the ip address:
set /p ipdizhi=
echo ip address is: %ipdizhi% (Y/N?)
set /p selection=
if %selection%==Y goto submask
if %selection%==N goto ipdizhi
:submask
echo please input the sub mask:
set /p submask=
echo sub mask is: %submask% (Y/N?)
set /p selection=
if %selection%==Y goto gateway
if %selection%==N goto submask
:gateway
echo please input the gateway address:
set /p gateway=
echo gateway address is: %gateway% (Y/N?)
set /p selection=
if %selection%==Y goto setip
if %selection%==N goto gateway
:setip
echo setting ip address is in progress......
netsh interface ipv4 set address "本地连接" static %ipdizhi% %submask% %gateway%
if %errorlevel%==0 (netsh interface ipv4 show ip) else (echo ---------------------Setting Error-----------------&echo erro code:%ERRORLEVEL%&echo ---------------------------------------------------)
echo continue the following dcntesting (Y/N?)
set /p selection=
if %selection%==Y goto restart
if %selection%==N goto end
:restart
echo.
set /p filename=please input the current contractor and station(e.g.816B-WKT):
echo your input is:%filename% (Y/N?)
set /p selection=
if %selection%==Y goto continue
if %selection%==N goto restart
:continue
echo now the ping tesing is in progress,please wait..........................
setlocal enabledelayedexpansion
for /f "tokens=1,2,3,4 delims= " %%i in (gateway.txt)do (set station= %%i
set contractor=%%j
set description=%%k
set ipaddr=%%l
for /f "delims=" %%m in ('ping -n 4 !ipaddr!^|find "TTL" ^&^& echo ping !ipaddr! 1 ^|^| echo ping !ipaddr! 0')do (
set str_ping=!date!!time! !station!-!contractor!-!description! %%m
echo !str_ping!>>!filename!.txt)
)
echo.
echo ping testing is completed,please check the result in current directory with filename !filename!.txt
echo.
:end
pause