windows 从 IPConfig 获取 IP 地址,稍后在代码中使用,或保存

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5414800/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 16:29:44  来源:igfitidea点击:

Get IP address from IPConfig, use later in code, or save

windowsbatch-fileip

提问by JShoe

Is it possible to run a code that searches IPConfig for the IP address then saves that to a text document or enters it into the prompt? I want to be able to plug my flash drive into a computer, run said batch file and either use that IP address or save it.

是否可以运行一个代码,在 IPConfig 中搜索 IP 地址,然后将其保存到文本文档或将其输入到提示中?我希望能够将我的闪存驱动器插入计算机,运行所述批处理文件并使用该 IP 地址或保存它。

采纳答案by ultifinitus

FULL code

完整代码

@ECHO OFF
ECHO.


FOR /F "TOKENS=2* DELIMS=:" %%A IN ('IPCONFIG ^| FIND "IPv4"') DO FOR %%B IN (%%A) DO SET IPADDR=%%B
ECHO %IPADDR% > file.txt



:End

The previous code will store your local ip into file.txt

前面的代码会将您的本地 ip 存储到 file.txt 中

回答by Rafael Colucci

Just run the follow

只需运行以下

IpConfig >> C:\myip.txt

IpConfig >> C:\myip.txt