简体   繁体   English

通过编程将本地网络IP放入命令提示符

[英]Get local network IP programmatically into command prompt

Just as others have asked for other languages, I would like to know how I get the local network IP into the command line (Windows 7) without passing it as a parameter. 就像其他人要求其他语言一样,我想知道如何将本地网络IP传递到命令行(Windows 7)中而不将其作为参数传递。 From this I know it is not saved as an environment variable, although I can see: 由此我知道它没有保存为环境变量,尽管我可以看到:

USERDNSDOMAIN=COMPANY.LOCAL
USERDOMAIN=COMPANY

I want to write a script that passes the local network IP address to a Java program and I cannot access the Java program itself. 我想编写一个将本地网络IP地址传递给Java程序的脚本,但无法访问Java程序本身。

EDIT: No, ipconfig won't do because I would have to parse the result. 编辑:不, ipconfig不会做,因为我必须解析结果。 I want a single variable. 我想要一个变量。

This will get the IPv4 address of a network adapter. 这将获取网络适配器的IPv4地址。 You may have to add more find statements to filter out some IP addresses of irrelevant adapters 您可能必须添加更多的find语句来过滤掉不相关的适配器的某些IP地址

for /F "delims=: tokens=2" %%G IN ('ipconfig^|find "IPv4"^|find /v " 169."') DO (set IP=%%G)
echo %IP%
pause

Alternatively, you can try parsing the output of netstat in a similar way 另外,您可以尝试以类似方式解析netstat的输出

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM