How to Get Your Public IP Address from the Command Line, Powershell, or Bash Shell

Published on Aug. 22, 2023, 12:14 p.m.

Why would you want to get your IP address from the command line when you can easily look it up in the GUI? The real reason, though, is that you’re probably going to automate it in a script.

Get Local (Private) IP address from CMD (Command Prompt)

To find your local or private IP address from the command prompt in Windows, open up the start menu, search for the Command prompt, open it up, and type the following command:

ipconfig

Please note this is not the public address that websites will see your traffic coming from.

How to Get Public (External) IP address from CMD (Command Prompt)

To find your public / external IP address from the command prompt, you have a lot of different options, but perhaps the easiest one is to simply type the following command.

curl ifconfig.me

This command will make your current public IP address right there on the command line.

Curl should work from within the regular Windows CMD prompt inside of Windows 10 or 11 as well.

How to Get Public IP Address from Powershell

Here’s how to get your public IP address from a more powerful PowerShell prompt (or script, for that matter).

(Invoke-WebRequest -UseBasicParsing -URI ifconfig.me ).Content

It’ll instantly return your IP address.

$myip = Invoke-WebRequest -UseBasicParsing -URI ifconfig.me
$myip.Content

This will create the $myip variable and put the contents of the request into it, and then you can use $myip.Content in a script if you need to.

How to Get Public IP Address from the Bash Shell

following command:

curl ifconfig.me

It should work exactly the same way as the command in the regular CMD prompt.