日期:2014-05-17  浏览次数:20761 次

请问批处理中如何把找到的ip地址赋给一个变量?
route print如下
Network Destination Netmask Gateway Interface Metric
  0.0.0.0 0.0.0.0 192.168.1.1 192.168.1.12 25
  127.0.0.0 255.0.0.0 127.0.0.1 127.0.0.1 1


route print|findstr 那个红色的地址
即interface下第一个ip地址,赋给一个定义的变量。

------解决方案--------------------
BatchFile code

@echo off
for /f "tokens=4" %%a in ('route print^|findstr "0.0.0.0.*0.0.0.0"') do (
    set IP=%%a
    goto :Print
)
:Print
echo IP地址:%IP%

------解决方案--------------------
"^"是用做转义的,

就像C语言里,用\n表示换行,用\\表示显示一个"\",