From morten, 2 Years ago, written in PowerShell.
Embed
  1. # Check Public IP-script
  2. #
  3. $CurrentIP = "xx.xx.xx.xx"
  4. $apikey = "xx"
  5. $credentials = New-Object System.Management.Automation.PSCredential ($apiKey, (ConvertTo-SecureString $apiKey -AsPlainText -Force))
  6.  
  7.  
  8. $ifconfig = Invoke-WebRequest ifconfig.co/json | ConvertFrom-Json
  9.  
  10. if ($ifconfig.IP -ne $CurrentIP) {
  11.     'new ip!'
  12.     $pushDevices = Invoke-RestMethod -Uri 'https://api.pushbullet.com/api/devices' -Method Get -Credential $credentials
  13.     foreach ($device in $pushDevices.devices) {
  14.  
  15.         # build the notification
  16.         $notification = @{
  17.             device_iden = $device.iden
  18.             type = 'note'
  19.             title = 'IP Address Change detected'
  20.             body = "New IP address $($ifconfig.ip) is detected"
  21.         }
  22.         Invoke-RestMethod -Uri 'https://api.pushbullet.com/api/pushes' -Body $notification -Method Post -Credential $credentials
  23.     }
  24. }