本帖最后由 bigjohn 于 2019-6-15 17:58 编辑
- @echo off
- setlocal enabledelayedexpansion
- set count=0
- set lost=0
- set totallost=10
-
- if exist temp.txt del temp.txt
- if exist temp1.txt del temp1.txt
- if exist lost.txt del lost.txt
- if exist offline.txt del offline.txt
-
-
- for /f "usebackq delims=" %%a in (ip.txt) do (
- echo %%a>temp.txt
-
- set /a count+=1
- set /p = !count!.
- set /p = No.!count! >>temp1.txt
-
- for /f "tokens= 1 delims= " %%i in (temp.txt) do set /p = %%i
- for /f "tokens= 1 delims= " %%i in (temp.txt) do set /p = "%%i " >>temp1.txt
-
- for /f "tokens= 2 delims= " %%i in (temp.txt) do set /p = "%%i "
- for /f "tokens= 2 delims= " %%i in (temp.txt) do set /p = "%%i " >>temp1.txt
-
- set b = %%a
-
- for /f "tokens=3 delims=," %%i in ('ping -n 1 "%b%"^|findstr /i "数据包 平均"') do set /p = "%%i "
- for /f "tokens=3 delims=," %%i in ('ping -n 1 "%b”^|findstr /i "数据包 平均"') do set /p = "%%i " >>temp1.txt
-
-
-
- echo. >>temp1.txt
- echo.
- echo.
-
- )<nul
-
-
- for /f "usebackq delims=" %%a in (temp1.txt) do (
-
- for /f "tokens=6 delims= " %%i in ('echo %%a^|findstr /i "丢失"') do (
- if %lost%==%%i echo %%a >> lost.txt rem 调试用,不正确
- if %totallost%==%%i echo %%a >> offline.txt rem 调试用,不正确
- )
-
- )<nul
复制代码 以上是我的程序,不知道为什么有时temp1.txt结果正确,有时就不正确。
新手上路,不太会用变量,只好不停地打开文件得到变量,执行效率非常低。
见笑了。 |