1.获取本地公网IP并写入本地HOSTS
@findstr /v "wjxy.net.cn" %windir%\System32\Drivers\Etc\hosts > %tmp%\hosts & @type %tmp%\hosts > %windir%\System32\Drivers\Etc\hosts
//删除hosts文件中含有wjxy.net.cn的行
@FOR /F %%i IN ('curl -l -s members.3322.org/dyndns/getip') DO @echo %%i 1.test.com > %windir%\System32\Drivers\Etc\hosts
2. 获取网站IP并显示
@FOR /F "skip=2 tokens=2" %%i IN ('ping -n 1 h1.wjxy.net.cn') DO @echo %%i &goto :EOF
//skip=2 表示跳过2行 tokens=2取第二列值
//goto :eof退出循环
或者使用下面方法
@Echo Off&Setlocal Enabledelayedexpansion
For /f "delims=" %%i in (1.txt) do (
Set /a n+=1
If !n!==2 Echo %%i
)
Pause
3.查找包含字符串的行,并显示其中某列的值
@FOR /F "tokens=2" %%i IN ('ping -n 1 h1.wjxy.net.cn ^|find "来自"') DO @echo %%i