有没有办法通过命令提示符完成此操作,而不使用任何第三方软件或依赖于PowerShell?
像在Linux / Mac上使用的 curl http://ipinfo.io/ip
这样的简单命令就很好了。
谢谢!
有没有办法通过命令提示符完成此操作,而不使用任何第三方软件或依赖于PowerShell?
像在Linux / Mac上使用的 curl http://ipinfo.io/ip
这样的简单命令就很好了。
谢谢!
最简单的跨平台解决方案(适用于Mac、Windows和Linux)
curl "http://myexternalip.com/raw"
& 您将获得公共IPv4。
git bash
-> C:\Program Files\Git\mingw32\bin\curl.exe
或者 xampp
-> C:\xampp\apache\bin\curl.exe
,那么curl也会被安装。 - Gray Programmerz以下命令在Windows和Linux中都可以使用:
curl ifconfig.me
Curl是内置在Windows中的,当你升级到最新版本时,它不被称为第三方软件。
或者
curl ifconfig.co
在Linux中,几乎所有的发行版都已经有这个命令了。
非常感谢ArthurG提供的这些命令,它们完美地运行,并且可以在批处理脚本中以多种方式使用。
curl ip-adresim.app
它支持IPv4和IPv6。
尝试使用这个普通的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%
nslookup myip.opendns.com. resolver1.opendns.com
一行命令,无需使用curl或powershell,只需使用裸的CMD,输入IPv4地址即可。
FOR /f "skip=1 tokens=2 delims=:\ " %G IN ('nslookup myip.opendns.com resolver1.opendns.com 2^>^&1 ^|find "dress"') DO @echo %G
实际上,在Linux和Windows中,您可以使用完全相同的命令:
curl http://ipinfo.io/ip
我将它作为批处理文件的一部分使用,如下所示:
FOR /F "tokens=* USEBACKQ" %%F IN (`curl http://ipinfo.io/ip`) DO (
SET currentip=%%F
)
ECHO %currentip%
Windows/Linux 版本:
nslookup myip.opendns.com resolver1.opendns.com
Unix版本:
dig +short myip.opendns.com @resolver1.opendns.com
nslookup
、dig
和 host
这三个命令,但是在某些系统中只有一个或其中几个是标准安装(尽管在我的 Mac 上,这三个命令都在 /usr/bin
中;但这可能是 XCode 的一部分)。“nslookup” 曾经是 Windows 的一部分,但我猜现在不再是了。 - tripleeecurl 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%
myip.opendns.com
来提供此服务。可能应该明确说明答案;目前看起来像是“这是如何使用nslookup
”。 - tripleee