【发布时间】:2017-02-11 17:00:04
【问题描述】:
在不使用任何第三方软件或依赖 powershell 的情况下通过命令提示符执行此操作的任何方式?
一个简单的命令就像在我使用 curl http://ipinfo.io/ip 的 Linux/Mac 上一样。
谢谢!
【问题讨论】:
标签: windows shell ip ip-address command-prompt
在不使用任何第三方软件或依赖 powershell 的情况下通过命令提示符执行此操作的任何方式?
一个简单的命令就像在我使用 curl http://ipinfo.io/ip 的 Linux/Mac 上一样。
谢谢!
【问题讨论】:
标签: windows shell ip ip-address command-prompt
【讨论】:
myip.opendns.com。也许答案应该说明这一点;就目前而言,它看起来像“这是如何使用nslookup”。
最简单的方法是按照命令开火
curl "http://myexternalip.com/raw"
&您将获得公共 IPV4。
【讨论】:
git bash -> C:\Program Files\Git\mingw32\bin\curl.exe or xampp -> C:\xampp\apache\bin\curl.exe
在正常的 dos 批处理中试试这个
@echo off
nslookup myip.opendns.com resolver1.opendns.com | find "Address" >"%temp%\test1.txt"
more +1 "%temp%\test1.txt" >"%temp%\test2.txt"
set /p MyIP=<%temp%\test2.txt
del %temp%\test2.txt
set MyIP=%MyIP:~10%
echo %MyIP%
现在,%MyIP% 可以回显或用作变量以供其他批处理使用。
【讨论】:
这个命令对我有用:
nslookup myip.opendns.com. resolver1.opendns.com
【讨论】:
curl ip-adresim.app
它同时支持 IPv4 和 IPv6。
【讨论】:
您可以在 Windows 和 Linux 中使用这些命令
curl ifconfig.me
Curl是升级到最新版本时Windows内置的东西,所以不叫第三方软件。
或
curl ifconfig.co
在 Linux 中,几乎 Distros 已经有了这个命令。
非常感谢 ArthurG 的命令。它工作完美,可以多种方式用于批处理脚本。
【讨论】:
Windows/Linux 版本:
nslookup myip.opendns.com resolver1.opendns.com
Unix 版本:
dig +short myip.opendns.com @resolver1.opendns.com
【讨论】:
dig 没有什么特别的“Unix”;还有host。 nslookup、dig 和 host 中的所有三个通常都安装在 Unix / Linux / Mac 上,尽管通常最多其中一个将成为任何给定平台上标准安装的一部分(尽管在我的 Mac 上,我在/usr/bin 中拥有所有三个;但也许这是 XCode 的一部分)。 nslookup 曾经是基本 Windows 安装的一部分,但我猜这可能不再是真的。
这对我来说非常适合:
curl http://ip.jsontest.com/ > ip.json
for /f "tokens=2 delims=:" %%a in ('type ip.json') do (set publicip=%%a)
set publicip=%publicip:{=%
set publicip=%publicip:}=%
set publicip=%publicip:"=%
echo %publicip:~1%
【讨论】: