Compare commits
2 Commits
c0f0bde6cf
...
e4f5e7aa40
| Author | SHA1 | Date | |
|---|---|---|---|
| e4f5e7aa40 | |||
| 7f65239431 |
@@ -40,4 +40,48 @@ else {
|
|||||||
Write-Host -ForegroundColor Green "No change!"
|
Write-Host -ForegroundColor Green "No change!"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
=======
|
||||||
|
# Check Public IP-script
|
||||||
|
#
|
||||||
|
#function Check-ChangedIP {
|
||||||
|
param (
|
||||||
|
$Domain,$Alert=$false
|
||||||
|
)
|
||||||
|
|
||||||
|
$apikey = "xx"
|
||||||
|
|
||||||
|
# Script starts
|
||||||
|
$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
|
||||||
|
|
||||||
|
if ($ifconfig.IP -ne $CurrentIP) {
|
||||||
|
'new ip!'
|
||||||
|
if ($Alert -eq $true) {
|
||||||
|
$pushDevices = Invoke-RestMethod -Uri 'https://api.pushbullet.com/api/devices' -Method Get -Credential $credentials
|
||||||
|
foreach ($device in $pushDevices.devices) {
|
||||||
|
|
||||||
|
# build the notification
|
||||||
|
$notification = @{
|
||||||
|
device_iden = $device.iden
|
||||||
|
type = 'note'
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Write-Host -ForegroundColor Red "New IP detected!"
|
||||||
|
Write-Host -ForegroundColor Red "Old: $CurrentIP"
|
||||||
|
Write-Host -ForegroundColor Red "New: $($ifconfig.ip)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Write-Host -ForegroundColor Green "No change!"
|
||||||
|
}
|
||||||
|
|
||||||
|
>>>>>>> c0f0bde6cf363f87c1f0213243a1d7ed173203e5
|
||||||
#}
|
#}
|
||||||
Reference in New Issue
Block a user