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 for.
Thanks!
9 Answers
Use the Invoke-WebRequest module in powershell. For example:
Invoke-WebRequest Edit: I misread the question and thought you needed to use Powrshell.
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.
5Simplest way & Cross platform solution (Mac, Windows, and Linux)
curl ""
& You Will get public IPV4.
1you 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.
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.
0This command works for me:
nslookup myip.opendns.com. resolver1.opendns.com 0curl ip-adresim.app It supports both IPv4 and IPv6.
Windows/Linux version:
nslookup myip.opendns.com resolver1.opendns.com Unix version:
dig +short myip.opendns.com @resolver1.opendns.com 2This works perfectly for me:
curl > 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% 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