How to Find Your IP Address on Windows Using the Command Line

Posted: | Tags: Windows

This article explains how to find your private (local) and public IP addresses on Windows using the command line.

You can use either Command Prompt (cmd.exe) or PowerShell (powershell.exe) to run the necessary commands.

If you're using macOS, see the following article for instructions:

Find your private IP address

On Windows, you can use the ipconfig command to display your network configuration details. This works the same in both Command Prompt and PowerShell.

Here’s an example of the output from ipconfig. Look for the line labeled "IPv4 Address" — this is your private IP address.

C:\> ipconfig
Windows IP Configuration


Wireless LAN adapter Wi-Fi:

   Connection-specific DNS Suffix  . : example.com
   IPv6 Address. . . . . . . . . . . : XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX
   Temporary IPv6 Address. . . . . . : XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX
   Link-local IPv6 Address . . . . . : fe80::XXXX:XXXX:XXXX:XXXX%XX
   IPv4 Address. . . . . . . . . . . : 192.168.XXX.XXX
   Subnet Mask . . . . . . . . . . . : XXX.XXX.XXX.XXX
   Default Gateway . . . . . . . . . : fe80::XXXX:XXXX:XXXX:XXXX%XX
                                      192.168.XXX.XXX

Find your public IP address

There are several websites that will show your public IP address when accessed. One example is a site provided by AWS:

Starting with Windows 10, the curl command is built-in. You can use it in either Command Prompt or PowerShell to get your public IP:

C:\> curl checkip.amazonaws.com
XXX.XXX.XXX.XXX

In PowerShell 7, curl works as expected. However, in PowerShell 5 and earlier, curl is an alias for Invoke-WebRequest, which may include extra metadata in the output.

To get just the IP address, you can explicitly run curl.exe instead.

C:\> curl.exe checkip.amazonaws.com
XXX.XXX.XXX.XXX

Note that checkip.amazonaws.com returns the IP address from the X-Forwarded-For header if it is present, which can result in an inaccurate reading of your actual public IP address, especially in testing scenarios.

C:\> curl checkip.amazonaws.com --header "X-Forwarded-For: 0.0.0.0"
0.0.0.0

If you need a service that ignores the X-Forwarded-For header, consider using the following:

C:\> curl ifconfig.io
XXX.XXX.XXX.XXX
C:\> curl ifconfig.io --header "X-Forwarded-For: 0.0.0.0"
XXX.XXX.XXX.XXX

Related Categories

Related Articles