Windows OS Hub
  • Windows
    • Windows 11
    • Windows Server 2022
    • Windows 10
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
  • PowerShell
  • Linux
  • Home
  • About

Windows OS Hub

  • Windows
    • Windows 11
    • Windows Server 2022
    • Windows 10
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
  • PowerShell
  • Linux

 Windows OS Hub / PowerShell / How to Get My Public IP Address with PowerShell

October 24, 2023

How to Get My Public IP Address with PowerShell

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:

  • http://ipinfo.io/ip
  • http://ifconfig.me/ip
  • http://icanhazip.com
  • http://ident.me

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:

(curl ifconfig.me).content

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 Invoke-WebRequest command returns an error on Windows computers with Internet Explorer disabled (uninstalled) and on Windows Server Core installations:

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
$wc.DownloadString("http://myexternalip.com/raw")

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

get my public ip from opendns using powershell

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.

Learn how to authenticate to a proxy server from PowerShell.
7 comments
13
Facebook Twitter Google + Pinterest
PowerShellWindows 10Windows Server 2019
previous post
How to See Number of Active User Sessions on IIS WebSite
next post
Error 0x80073CFA: Can’t Uninstall Apps using Remove-AppxPackage in Windows 10

Related Reading

How to See Number of Active User Sessions...

March 16, 2024

Disks and Partitions Management with Windows PowerShell

March 11, 2024

How to Create and Use a RAM Drive...

December 18, 2023

FTP Server Quick Setup on Windows 10/11 and...

March 16, 2024

How to Find Large Files on a Computer...

September 26, 2024

Implementing Dynamic Groups in Active Directory with PowerShell

October 3, 2024

How to Measure Storage Performance and IOPS on...

March 11, 2024

How Show a Pop-Up or Balloon Notification with...

April 10, 2024

7 comments

Genie September 23, 2020 - 2:25 am

Hi, great information! Just a slight correction to you second invocation with gps data, the command is missing the closing bracket )
Invoke-RestMethod -Uri (‘http://ipinfo.io/’+(Invoke-WebRequest -uri “http://ifconfig.me/ip”).Content)

Reply
Sheldon October 25, 2021 - 3:05 pm

_http://ident.me currently has been hacked and contains a trojan/malware as per Malwarebytes – 10/25/2021

Reply
Pierre Carrier February 17, 2022 - 1:27 pm

@sheldon that’s mistake on their part, there was no hack or malware.

Reply
Pixel Encounter March 7, 2022 - 3:39 pm

I would recommend using the parameter -UseBasicParsing as well, (Invoke-WebRequest -uri “http://ifconfig.me/ip” -UseBasicParsing).Content;

Reply
RandomInternetStranger March 2, 2023 - 8:53 pm

UseBasicParsing has been deprecated and applies to all requests. Per https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest?view=powershell-7.3#-usebasicparsing

Reply
F_BrKfast March 23, 2023 - 11:05 pm

Thanks Pixel Encounter!

UseBasicParsing was needed for the Powershell script to successfully run remotely through our RMM software. It wasn’t needed when running the script locally. I understand that the official word is that it’s no longer needed but the results showed otherwise.

Reply
Hashem October 27, 2023 - 2:22 pm

curl ifconfig.co

Reply

Leave a Comment Cancel Reply

join us telegram channel https://t.me/woshub
Join WindowsHub Telegram channel to get the latest updates!

Recent Posts

  • Map a Network Drive over SSH (SSHFS) in Windows

    May 13, 2025
  • Configure NTP Time Source for Active Directory Domain

    May 6, 2025
  • Cannot Install Network Adapter Drivers on Windows Server

    April 29, 2025
  • Change BIOS from Legacy to UEFI without Reinstalling Windows

    April 21, 2025
  • How to Prefer IPv4 over IPv6 in Windows Networks

    April 9, 2025
  • Load Drivers from WinPE or Recovery CMD

    March 26, 2025
  • How to Block Common (Weak) Passwords in Active Directory

    March 25, 2025
  • Fix: The referenced assembly could not be found error (0x80073701) on Windows

    March 17, 2025
  • Exclude a Specific User or Computer from Group Policy

    March 12, 2025
  • AD Domain Join: Computer Account Re-use Blocked

    March 11, 2025

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Managing Printers and Drivers on Windows with PowerShell
  • Implementing Dynamic Groups in Active Directory with PowerShell
  • How to Measure Storage Performance and IOPS on Windows
  • FTP Server Quick Setup on Windows 10/11 and Windows Server
  • Adding Multiple IP Addresses (Aliases) to a Single Network Adapter
  • Disks and Partitions Management with Windows PowerShell
  • Enable Access-based Enumeration (ABE) on Shared Folders (SMB)
Footer Logo

@2014 - 2024 - Windows OS Hub. All about operating systems for sysadmins


Back To Top