如何使用 CMD 或 PowerShell 获取代理服务器的 IP 地址

如何使用 CMD 或 PowerShell 获取代理服务器的 IP 地址

我使用代理应用程序(如 Psiphon 或 ProtonVPN)连接到互联网。我想获取我连接到互联网的 IP 地址。

我需要使用 CMD 或 PowerShell,因为稍后我想在 Autohotkey 中使用 IP 地址。

现在我已经寻找了很长时间的方法来做到这一点,我得出的结论是这是不可能的。但我决定问这个问题,因为我可能遗漏了一些东西。此外,任何解决方法或应用程序都会受到赞赏。

以下是我迄今为止尝试过的方法:

命令:

for /F "tokens=2" %i in ('"nslookup myip.opendns.com resolver1.opendns.com | find /i "address" | find /v "208.67.222.222""') do echo %i

此命令将打印我的真实 IP 地址,它不通过代理。

我发现它不起作用的原因是这样的: Windows,不是管理员:代理在 Firefox 中工作但在 cmd 中不工作,为什么?

因此,上述问题的答案声称 TCP 连接将被代理,因此我发现了这一点:

电源外壳:

Resolve-DnsName -Name myip.opendns.com -Server resolver1.opendns.com -TcpOnly

但这也不起作用。

答案1

您可以使用以下 PowerShell 命令通过 HTTP 使用 RESTful Web 服务获取您的公共 IP:

Invoke-RestMethod http://ipinfo.io/json | Select -exp ip

根据路由表配置等,此方法在某些情况下可能不起作用。

在这种情况下我很高兴它对你有帮助。

答案2

如果您的 Windows 10 版本是 17063 或更高版本,则使用cUrl.exe也可以。 C:\windows\system32\cUrl.exe

  • 电源外壳
$_pub_ip=curl ipecho.net/plain | sls [0-9]
$_pub_ip=curl icanhazip.com    | sls [0-9]
$_pub_ip=curl ifconfig.me      | sls [0-9]
$_pub_ip=curl ifconfig.co      | sls [0-9]

rem :: For proxy 
$_pub_ip=curl -x [your_ip_local |or| 127.0.0.1]:[door] http://ipecho.net/plain  | sls [0-9]
$_pub_ip=curl -x [your_ip_local |or| 127.0.0.1]:[door] http://ipecho.net/plain  | sls [0-9]
$_pub_ip=curl -x [your_ip_local |or| 127.0.0.1]:[door] http://icanhazip.com     | sls [0-9]
$_pub_ip=curl -x [your_ip_local |or| 127.0.0.1]:[door] http://ifconfig.me       | sls [0-9]
$_pub_ip=curl -x [your_ip_local |or| 127.0.0.1]:[door] http://ifconfig.co       | sls [0-9]
  • 命令/批处理
rem :: in command line :: 
@for /f tokens^=* %i in ('curl ipecho.net/plain -B -s')do @set "_pub_ip=%~i" && @call echo\%_pub_ip%

rem :: in bat/cmd file :: 
@for /f tokens^=* %%i in ('curl ipecho.net/plain -B -s')do @set "_pub_ip=%%~i" && @call echo\%_pub_ip%
  • 对于代理:
:: in command line ::
@for /f tokens^=* %i in ('curl -x [your_ip_local |or| 127.0.0.1]:[door] http://ipecho.net/plain -B -s')do @set "_pub_ip=%~i" && call echo\%_pub_ip%

:: in cmd/bat file ::
@for /f tokens^=* %%i in ('curl -x [your_ip_local |or| 127.0.0.1]:[door] http://ipecho.net/plain -B -s')do @set "_pub_ip=%%~i" && call echo\%_pub_ip%

[√]来源

相关内容