将 IP 地址写入文件
有没有简单的命令可以将ip地址写入文件?
我知道如何写入文件,但是有 sysvar 之类的东西吗!?
Is there any simple command to write the ip-address into a file?
I know how to write in a file, but is there a sysvar or something!?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
ipconfig | ipconfig | ipconfig找到“IP地址”> out.txt
您仍然需要从“IP 地址............: 0.0.0.0”中提取 IP 地址并修剪所有空格。
ipconfig | find "IP Address" > out.txt
You still need to extract the IP Address from "IP Address.............: 0.0.0.0" and trim any whitespace.
我能想到的最简单的:
Simplest i can think of:
这是您要找的吗?
Is this what you're looking for?
对于 Windows 7 计算机:
左引号和 IPv4 之间有三个空格字符,因为技术上该行以空格开头。我不知道在 findstr 命令之前删除它的方法。
请记住,即使从技术上讲它是正则表达式,Windows 命令行也不会像 C# 或其他方式那样解析它们。有一个可接受的序列/通配符列表(标记为 XP,但它在 Win7 环境中对我有用)此处。
我花了一些尝试和错误,但这只为您提供了分配的 IPv4 地址的行,而不是混乱其他 findstr 迭代结果的“自动配置”内容。
For Windows 7 machines:
There are three whitespace characters between the opening quotation mark and IPv4 since that line technically begins with whitespace. I am unaware of a way to strip that prior to the findstr command.
Remember that, even though it's technically regular expressions, the Windows command line doesn't parse them the same way as, say, C# or whatever. There's a list of the acceptable sequences/wildcards (marked for XP, but it worked for me in a Win7 environment) here.
Took me a little trial and error, but this gets you ONLY the lines for assigned IPv4 addresses, and not the "Autoconfigured" stuff that clutters the results of other findstr iterations.
这是一个可以完成这项工作的 vbs 脚本。请注意,这是针对外部 IP 地址的。只需在上面查找内部/本地 IP 地址即可。
这是代码。只需创建一个文本文档,粘贴它,然后将其重命名为something.vbs
我不将此脚本归功于我,我只是在我的计算机上的一个我很长时间没有碰过的文件夹中找到了它。
here is a vbs script that will do the job. Note that this is for the external IP address. Just look above for an internal/local ip address.
here is the code. just create a text document, paste this, and rename it to something.vbs
I do not take credit for this script, I just found it in a folder on my computer that I hadn't touched in a long time.
只需添加一点即可显示网关(您的路由器)并 ping 看看您的 DNS 是否正常工作:
Just added a little to also display the gateway (your router) and ping to see if your DNS is working: