从批处理文件获取默认网关 [英] Get Default Gateway from Batch file

查看:365
本文介绍了从批处理文件获取默认网关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想返回默认网关,就像我对IPv4一样,但是它返回空白.

I want to return the Default Gateway like i have for the IPv4 but it returns Blank.

for /f "tokens=1-2 delims=:" %%a in ('ipconfig^|find "IPv4"') do set ip=%%b
set ip=%ip:~1%
echo.
echo  IP Address is: %ip%
echo.

这是我到目前为止的内容,但是它返回空白,我尝试更改它,但是它仍然返回空白答案.

This is what i have so far but it returns blank, i have tried to alter it but it still returns a blank answer.

for /f "tokens=1-2 delims=:" %%a in ('ipconfig^|find "Default"') do set ip=%%b
set ip=%ip:~2%
echo.
echo  The Gateway is: %ip%
echo.

任何想法我该怎么做.并返回给定计算机的默认网关.

Any ideas how i can do this. and return the default gateway for a given Computer.

推荐答案

set "ip="
for /f "tokens=1-2 delims=:" %%a in ('ipconfig^|find "Default"') do if not defined ip set ip=%%b

看看ipconfig中的列表-可能有多个default行.因此,您将从包含default

Take a look at the listing from ipconfig - it's likely that there is more than one default line. You would therefore get the data from the last line containing default

上面的构造返回包含defaultfirst行.

The above construct returns the first line containing default.

这篇关于从批处理文件获取默认网关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆