Getting public IP on troubleshot networking issue is very useful. Especially, there is an issue with accessing your server from the external (public) network. Here is how to get your server’s public IP using PowerShell Invoke-RestMethod Command.
(Invoke-RestMethod -uri ipinfo.io/json).ip
Also, you can get the detail of your public IP by removing “ip” variable on the command above.
Invoke-RestMethod -uri ipinfo.io/json
There are numerous other services you can call to get the public IP, a few are below:
you can also get additional IP information, including the hostname, using ipinfo.io‘s JSON web service. You can also use ipinfo.io to get the IP information about another public IP Address. Just use the IP within the URL (ex: http://ipinfo.io/18.104.22.168/json)