2 Methods to Get Public IP Address on Windows

2 Methods to Get Public IP Address on Windows

When trying to solve network connectivity problems, may be useful to know public IP address of the machine. A public IP address is an IP address which is used for communication between hosts over the Internet. ISP assigns public address to the home's network. This tutorial shows how to get public IP address on Windows.

Method 1 - CMD

One of the fastest and recommended way to get public IP address of the machine, get it directly from a DNS server. Use nslookup command with an OpenDNS resolver to get public IP address:

nslookup myip.opendns.com resolver1.opendns.com

In order to print public IP address as sole output use for loop as follows:

for /f "skip=4 tokens=2" %a in ('nslookup myip.opendns.com resolver1.opendns.com 2^> nul') do @echo %a

Method 2 - PowerShell

To get public IP address in PowerShell, run the Resolve-DnsName command as follows:

Resolve-DnsName myip.opendns.com -Server resolver1.opendns.com | select -expand IP4Address

Leave a Comment

Cancel reply

Your email address will not be published.