windowsshellipip-addresscommand-prompt

How to obtain public ip address using windows command prompt?


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!


Solution

  • Use the Invoke-WebRequest module in powershell. For example:

    Invoke-WebRequest ifconfig.me/ip
    

    Go to source

    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.

    Go to source