Compare commits

...

3 Commits

Author SHA1 Message Date
d7b62549c7 Cleanup 2022-04-25 13:25:52 +02:00
e4f5e7aa40 first draft 2022-04-25 13:08:35 +02:00
7f65239431 First draft 2022-04-25 13:01:15 +02:00

View File

@@ -1,43 +1,42 @@
# Check Public IP-script # Check Public IP-script
# #
#function Check-ChangedIP { #function Check-ChangedIP {
param ( param (
$Domain,$Alert=$false $Domain,$Alert=$false
) )
$apikey = "xx" $apikey = "xx"
$gotify = ""
# Script starts
$CurrentIP = Resolve-DnsName $Domain | Select-Object -ExpandProperty Ipaddress # Script starts
$credentials = New-Object System.Management.Automation.PSCredential ($apiKey, (ConvertTo-SecureString $apiKey -AsPlainText -Force)) $CurrentIP = Resolve-DnsName $Domain | Select-Object -ExpandProperty Ipaddress
$credentials = New-Object System.Management.Automation.PSCredential ($apiKey, (ConvertTo-SecureString $apiKey -AsPlainText -Force))
$ifconfig = Invoke-WebRequest ifconfig.co/json | ConvertFrom-Json
$ifconfig = Invoke-WebRequest ifconfig.co/json | ConvertFrom-Json
if ($ifconfig.IP -ne $CurrentIP) {
'new ip!' if ($ifconfig.IP -ne $CurrentIP) {
if ($Alert -eq $true) { 'new ip!'
$pushDevices = Invoke-RestMethod -Uri 'https://api.pushbullet.com/api/devices' -Method Get -Credential $credentials if ($Alert -eq $true) {
foreach ($device in $pushDevices.devices) { $pushDevices = Invoke-RestMethod -Uri 'https://api.pushbullet.com/api/devices' -Method Get -Credential $credentials
foreach ($device in $pushDevices.devices) {
# build the notification
$notification = @{ # build the notification
device_iden = $device.iden $notification = @{
type = 'note' device_iden = $device.iden
title = 'IP Address Change detected' type = 'note'
body = "New IP address $($ifconfig.ip) is detected" title = 'IP Address Change detected'
} body = "New IP address $($ifconfig.ip) is detected"
Invoke-RestMethod -Uri 'https://api.pushbullet.com/api/pushes' -Body $notification -Method Post -Credential $credentials }
} Invoke-RestMethod -Uri 'https://api.pushbullet.com/api/pushes' -Body $notification -Method Post -Credential $credentials
} }
else { }
Write-Host -ForegroundColor Red "New IP detected!" else {
Write-Host -ForegroundColor Red "Old: $CurrentIP" Write-Host -ForegroundColor Red "New IP detected!"
Write-Host -ForegroundColor Red "New: $($ifconfig.ip)" Write-Host -ForegroundColor Red "Old: $CurrentIP"
} Write-Host -ForegroundColor Red "New: $($ifconfig.ip)"
} }
else { }
Write-Host -ForegroundColor Green "No change!" else {
} Write-Host -ForegroundColor Green "No change!"
}
#}