Super User Asked by Shayan on December 13, 2021
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:
CMD:
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
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:
PowerShell:
Resolve-DnsName -Name myip.opendns.com -Server resolver1.opendns.com -TcpOnly
But this also, doesn’t work.
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.
Answered by CraftyB on December 13, 2021
If your Windows 10 build is 17063, or later, using cUrl.exe
will also work.
C:windowssystem32cUrl.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%
[√] sources
Answered by iTwasnTme on December 13, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP