从IPConfig获取IP地址,稍后在代码中使用或保存 [英] Get IP address from IPConfig, use later in code, or save

查看:735
本文介绍了从IPConfig获取IP地址,稍后在代码中使用或保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

推荐答案

完整代码

@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

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

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

这篇关于从IPConfig获取IP地址,稍后在代码中使用或保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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