Get your public IP using PowerShell

0
Get your public IP using Powershell

Quick and simple one liner to get your public IP using Powershell via the code below

(Invoke-WebRequest -uri “https://www.theictguy.co.uk/ip/”).Content

You can take this one step further and have the script output to a text file My_Public_IP.txt which will be stored in the current working directory

(Invoke-WebRequest -uri “https://www.theictguy.co.uk/ip/”).Content | Out-File $PWD\My_Public_IP.txt

This can be taken even further to identify when your public IP Address has changed, set this as a start-up script and it will notify you on start-up.

Get your public IP using PowerShell
$MyCurrentIP = (Invoke-WebRequest -uri "https://www.theictguy.co.uk/ip/").Content
$MyPreviousIP = Get-Content $PWD\My_Public_IP.txt
if($MyCurrentIP -eq $MyPreviousIP) {
write-host "Your IP Address has not changed"
} else {
(Invoke-WebRequest -uri "https://www.theictguy.co.uk/ip/").Content | Out-File $PWD\My_Public_IP.txt
$ButtonType = 0
$Timeout = 60
$Confirmation = New-Object -ComObject wscript.shell
$Confirmation.popup("Your IP Address has changed to $MyCurrentIP. New IP Address written to My_Public_IP.txt",$Timeout,"Public IP has changed",$ButtonType)
}

Found priceless insights in this blog? Support the author’s creativity – buy them a coffee!

Leave a Reply

Your email address will not be published. Required fields are marked *