Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu

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

October 24, 2023 PowerShellWindows 10Windows Server 2019

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
6
Facebook Twitter Google + Pinterest
previous post
Remote IIS Management in Windows Server 2016/2012 R2
next post
Error 0x80073CFA: Can’t Uninstall Apps using Remove-AppxPackage in Windows 10

Related Reading

Zabbix: How to Get Data from PowerShell Scripts

October 27, 2023

Tracking Printer Usage with Windows Event Viewer Logs

October 19, 2023

PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

October 15, 2023

How to Query and Change Teams User Presence...

October 8, 2023

How to Use Ansible to Manage Windows Machines

September 25, 2023

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

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMWare
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • Zabbix: How to Get Data from PowerShell Scripts

    October 27, 2023
  • Tracking Printer Usage with Windows Event Viewer Logs

    October 19, 2023
  • PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

    October 15, 2023
  • Reset Root Password in VMware ESXi

    October 12, 2023
  • How to Query and Change Teams User Presence Status with PowerShell

    October 8, 2023
  • How to Increase Size of Disk Partition in Ubuntu

    October 5, 2023
  • How to Use Ansible to Manage Windows Machines

    September 25, 2023
  • Installing Language Pack in Windows 10/11 with PowerShell

    September 15, 2023
  • Configure Email Forwarding for Mailbox on Exchange Server/Microsoft 365

    September 14, 2023
  • How to View and Change BIOS (UEFI) Settings with PowerShell

    September 13, 2023

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Managing Printers and Drivers with PowerShell in Windows 10 / Server 2016
  • Active Directory Dynamic User Groups with PowerShell
  • Assign Multiple IP Addresses (Aliases) to a Single NIC
  • How to Measure Storage Performance and IOPS on Windows?
  • Disks and Partitions Management with Windows PowerShell
  • How to Create a RAM Disk on Windows Server?
  • How to See Number of Active User Sessions on IIS site?
Footer Logo

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


Back To Top