I had this same question today, and I wasn't satisfied with the answers I saw here or on Google, so I wrote a PowerShell script to send me a Slack notification whenever my IP address changes.
If you'd prefer to receive an email, you could click the links in the script to look at a different version that supports Outlook emails.
I hope this helps someone and earns a vote. :-)
Save the following text to a .ps1 file. Edit it as appropriate with your own Slack webhook URL. Save. Right-click the file to "Run with PowerShell".
Or you can schedule it to run daily or however often.
#Script to compare current IP with old IP and sends Slack notification if different (and do nothing if there was no change).
#We can put this as a scheduled task to run daily.
#ScriptName: IP_change_detection_notification.ps1
$slackWebhookUrl = "XXXXXXXXXX" #put yours here
$ipDetectionUrl = "https://wtfismyip.com/text"
$IPAddFile = "C:\code\IP_change_detection_notification.dat" #absolute path to file that stores the old IP record
$slackOutputFile = "C:\code\IP_change_detection_notification_Slack.txt"
$optionalDebuggingFile = "C:\code\IP_change_detection_notification_debugging.txt"
$Request = Invoke-WebRequest $ipDetectionUrl
$IP_new = ($Request.Content.Trim())
Write-Host "Current IP address: [$IP_new]"
#Check if old IP record exists
If(Test-Path "$IPAddFile")
{
#Get old IP
$IP_old = Get-Content "$IPAddFile"
#Compare IPs
if(-not($IP_new -eq $IP_old))
{
Write-Host "Old IP address: [$IP_old]"
$msg = "Your WAN IP has changed to $IP_new (was $IP_old)!"
Write-Host "$msg"
$body = $("{""text"":""$msg""}")
Write-Host "$body"
Invoke-RestMethod -Uri $slackWebhookUrl -Method Post -ContentType 'application/json' -Body $body -OutFile $slackOutputFile
"Notification Sent"
#Overwrite and update new IP
$IP_new | Out-File $IPAddFile
}
else
{"No change, no notification"}
}
else
{
#Create new, as file not found
$IP_new | Out-File $IPAddFile
"File created"
}
$(get-date -f yyyy-MM-dd_HH_mm_ss) | Out-File $optionalDebuggingFile
#Read-Host -Prompt "Press Enter to exit" #Comment out this line if this script will be run by a cron job. Otherwise, uncomment it so that you can see the results of the script in the console.
#This script was adapted from https://gallery.technet.microsoft.com/scriptcenter/Detect-IP-address-change-aeb51118 by Satyajit
To get the Task Scheduler working:
I had to run PowerShell as an administrator and then run Get-ExecutionPolicy
, which then told me that my current ExecutionPolicy was "Restricted".
Then I ran Set-ExecutionPolicy RemoteSigned
(as shown here, but it makes me nervous: https://stackoverflow.com/a/26955050/470749).
Then from a basic Windows command prompt, I tried running the following command a couple times: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy ByPass -File "C:\code\IP_change_detection_notification.ps1"
(once to store the IP, and a second time to check whether it had changed).
(Until you get that to work, don't bother trying to use Task Scheduler.)
Then I scheduled a task with C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
as the program and -ExecutionPolicy ByPass -File C:\code\IP_change_detection_notification.ps1
as the Arguments.