You can use a simple PowerShell command to find out the current public IP address that your Windows computer uses to access the Internet. There are a large number of online services (sites) that can return your current IP address.
You can parse the contents of a Web page from any popular IP address discovery service by using the Invoke-WebRequest cmdlet. But it’s easier to use one of the web services that just return the IP address in plain text or JSON format.
You can use the following websites:
For example, to find out your current public IP address, from which you access the Internet, open the PowerShell console and run the command:
(Invoke-WebRequest -uri "http://ifconfig.me/ip").Content
Or use a shorter command:
This command returns to the console the public IP address that you are using to access the Internet.
Or even you can get your GeoIP data (such as country, city, region, postal code, and GPS coordinates).
Invoke-RestMethod -Uri ('http://ipinfo.io/'+(Invoke-WebRequest -uri "http://ifconfig.me/ip").Content
The response content cannot be parsed because the Internet Explorer engine is not available, or Internet Explorer’s first-launch configuration is not incomplete.
In this case, add the -UseBasicParsing parameter:
(Invoke-WebRequest -UseBasicParsing -uri "http://ifconfig.me/ip").Content
Or use the built-in WebClient class:
$wc = new-object System.Net.WebClient
You can also use the OpenDNS service to find out your external (white) IP address. It is configured always to return the IP address from which the request came for myip.opendns.com. To resolve your public IP through DNS, you can use PowerShell:
Resolve-DnsName -Name myip.opendns.com -Server resolver1.opendns.com
Or from the command line:
nslookup myip.opendns.com resolver1.opendns.com
You should be aware that in most cases the address received is not the real public (“white”) IP of your computer. This is usually either the external IP address of the router (when NAT is used), a dynamic IP address (issued by your ISP), or the address of the proxy server configured in Windows and used to access the Internet.