You might probably know that there are many websites that can find public IP address. We are pretty much familiar about how to get public IP address by going to those sites. That’s because it’s very simple. However it would be really interesting to get public IP address using PowerShell. Yes using a simple command you can find out what is the public IP address of the computer that you are working on.
Most of us know that an IP address of the system can be known by running a simple command. For Windows machines, you can run ipconfig and for Linux it’s ifconfig command. If you have an internet connection from your ISP, the system would be usually behind a router or a modem. Using router’s administration page, you can still find your public IP. You need to log in to your router and review the configuration.
Get Public IP Address Using PowerShell
Using PowerShell it is possible to get public IP address of the computer that you are using. Run the below PowerShell command to find the Public IP address.
(Invoke-WebRequest -uri "https://api.ipify.org/").Content
Wait a second I just got a weird error when i ran the above command. Nothing to worry here, it’s just that you haven’t opened the Internet Explorer on your computer yet. The command says Internet Explorer engine is not available or it’s first launch configuration is not complete. Seems like after installing the OS, I never launched internet explorer.
Note – Invoke-WebRequest requires PowerShell version 3.0 or later.
So to fix this, open Internet Explorer and close it. Run the command again and you should see no errors.
Invoke-WebRequest : The response content cannot be parsed because the Internet Explorer engine is not available, or Internet Explorer's first-launch configuration is not complete. Specify the UseBasicParsing parameter and try again.
In the above command, we used api.ipify.org to find public IP address. In addition to that uri, there are several other options available. You can use any of the following sites to get the public IP address. Simply substitute any of these links in the command.
Furthermore, it is possible to get little more details about your internet service provider. You can run the below PowerShell command to find out details such as.
- IP Address
Invoke-RestMethod -Uri ('https://ipinfo.io/')