Any way of doing this through the command prompt without using any third party software or relying on powershell?
A simple command would be great like on Linux/Mac which I use curl http://ipinfo.io/ip
for.
Thanks!
Any way of doing this through the command prompt without using any third party software or relying on powershell?
A simple command would be great like on Linux/Mac which I use curl http://ipinfo.io/ip
for.
Thanks!
Use the Invoke-WebRequest module in powershell. For example:
Invoke-WebRequest ifconfig.me/ip
Edit: I misread the question and thought you needed to use Powershell, there is no built in command in cmd.exe
to return a public IP address, but you can use nslookup
to resolve it, like so;
nslookup myip.opendns.com. resolver1.opendns.com
Another option for the OP:
telnet curlmyip.com 80
Type GET
after you are connected.
Note: telnet is not installed/enabled by default on Windows.
myip.opendns.com
. Probably the answer should spell this out; as it stands, it looks like "here's how to use nslookup
". –
Stereophonic Simplest way & Cross platform solution (Mac, Windows, and Linux)
curl "http://myexternalip.com/raw"
& You Will get public IPV4.
git bash
-> C:\Program Files\Git\mingw32\bin\curl.exe
or xampp
-> C:\xampp\apache\bin\curl.exe
–
Kultur you can use these commands in both Windows and Linux
curl ifconfig.me
Curl is something that is built-in Windows when you upgrade to the latest version, so it's not called a third-party software.
or
curl ifconfig.co
In Linux, almost Distros have this command already.
Thanks so much ArthurG for your commands. It works perfectly and can be used for Batch script in many ways.
curl ip-adresim.app
It supports both IPv4 and IPv6.
Try this for normal dos batch
@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%
Now, %MyIP% will can be echo or used as a variable for additional batch use.
This command works for me:
nslookup myip.opendns.com. resolver1.opendns.com
Oneliner, no curl or powershell, just bare CMD, raw ip for IP4
FOR /f "skip=1 tokens=2 delims=:\ " %G IN ('nslookup myip.opendns.com resolver1.opendns.com 2^>^&1 ^|find "dress"') DO @echo %G
Actually you could use the very same command, both in Linux and Windows:
curl http://ipinfo.io/ip
I use it as part of a batch file like so:
FOR /F "tokens=* USEBACKQ" %%F IN (`curl http://ipinfo.io/ip`) DO (
SET currentip=%%F
)
ECHO %currentip%
another way is call this url in CURL in cmd or other command lines
curl ip.dnslab.link
response will be like this json
84.241.47.110
Windows/Linux version:
nslookup myip.opendns.com resolver1.opendns.com
Unix version:
dig +short myip.opendns.com @resolver1.opendns.com
dig
; there is also host
. All three of nslookup
, dig
, and host
are commonly installed on Unix / Linux / Mac, though typically at most one of them will be part of the standard install on any given platform (though on my Mac, I have all three in /usr/bin
; but maybe that's part of XCode). nslookup
used to be part of the base Windows install but I'm guessing this may no longer be true, either. –
Stereophonic This works perfectly for me:
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%
© 2022 - 2024 — McMap. All rights reserved.