I use a proxy application (like Psiphon or ProtonVPN) to connect to the internet. I want to get my IP address that I'm connected to the internet with.

I need to use CMD or PowerShell because later on, I want to use the IP address in Autohotkey.

Now I've been searching for ways to do this for a very long time, and I came to the conclusion that it's not possible. But I decided to ask this question because I could be missing something. Also, any workaround or application is apprecaited.

Here's what I've tried so far:


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

This command will print my real IP address, it doesn't go through the proxy.

And the reason it doesn't work, I found out, is this: Windows, not admin: Proxy working in Firefox but not in cmd, why?

So the answer on question above, claims a TCP connection would be proxied so I found this:


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

But this also, doesn't work.

  • 2
    I dont use either of the softwares mentioned above but please try this in powershell - Invoke-RestMethod http://ipinfo.io/json | Select -exp ip – CraftyB Apr 23 at 16:27
  • @CraftyB Awesome! It worked! Would you please write an answer? Been searching for this for so long! Thanks a lot. – Shayan Apr 23 at 19:36
  • You basically need to connect to an external website and ask it to return the IP address you requested data from. But if you are using a proxy/VPN that diverts all traffic on your machine through that proxy/VPN there should be a new interface on your machine that has that new proxy/VPN address. I am not an Windows person, but if there is a way to check the IP addresses of all interfaces on the command line, then check that and one of those addresses has to be the one for the proxy/VPN. This method is cleaner since it doesn’t rely on a remote service. – Giacomo1968 Apr 24 at 3:29
  • 1
    @JakeGould I know that! The softwares I mentioned on the very first line of the question, make an internal loopback address ( and use this as the proxy server, then the applications connect you to whatever the actual proxy web servers are. So this method doesn't work. – Shayan Apr 24 at 4:02

You can use the following PowerShell command to obtain your public IP via HTTP using a RESTful web service:

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

Its likely that this method may not work in some cases depending on routing table configurations etc.

In this case I'm glad it's helped you.

| improve this answer | |
  • Work for me too, with no proxy...+ – It Wasn't Me Apr 24 at 21:56

If your Windows 10 build is 17063, or later, using cUrl.exe will also work. C:\windows\system32\cUrl.exe

  • PowerShell
$_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|]:[door] http://ipecho.net/plain  | sls [0-9]
$_pub_ip=curl -x [your_ip_local |or|]:[door] http://ipecho.net/plain  | sls [0-9]
$_pub_ip=curl -x [your_ip_local |or|]:[door] http://icanhazip.com     | sls [0-9]
$_pub_ip=curl -x [your_ip_local |or|]:[door] http://ifconfig.me       | sls [0-9]
$_pub_ip=curl -x [your_ip_local |or|]:[door] http://ifconfig.co       | sls [0-9]
  • CMD/Batch
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%
  • For proxy:
:: in command line ::
@for /f tokens^=* %i in ('curl -x [your_ip_local |or|]:[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|]:[door] http://ipecho.net/plain -B -s')do @set "_pub_ip=%%~i" && call echo\%_pub_ip%

[√] sources

| improve this answer | |
  • 1
    @Shayan try this too: curl -x [your_ip_local]:8080 http://ipecho.net/plain – It Wasn't Me Apr 24 at 4:22
  • You sir, are a genius, it worked! Thanks a lot! I tried curl -x http://ipecho.net/plain Because 2040 is the port I set up for my proxy server to work on. – Shayan Apr 24 at 4:28
  • @Shayan good to know! I'm not genius, sorry sources – It Wasn't Me Apr 24 at 4:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.