diff --git a/TestURL.ps1 b/TestURL.ps1 index b208df4..04507e8 100644 --- a/TestURL.ps1 +++ b/TestURL.ps1 @@ -13,11 +13,23 @@ $hastebinUrl = "https://haste.nixc.us/documents" $ntfyServer = "https://ntfy.nixc.us/bnHobG80sO5ZF4SB" $ntfyCredentials = "admin:tiZcgc8Waf9mg5A4n2aJ4Qk2RyYnwEHDT" +# Retrieve hostname, OS information, and external IP addresses +$hostname = $env:COMPUTERNAME +$osInfo = Get-CimInstance Win32_OperatingSystem | Select-Object -ExpandProperty Caption +$externalIPv4 = (Invoke-RestMethod -Uri "https://ifconfig.me/ip" -Method Get -UseBasicParsing -ErrorAction SilentlyContinue) -replace '\s+', '' -replace '\n', '' +$externalIPv6 = (Invoke-RestMethod -Uri "https://ifconfig.me/ipv6" -Method Get -UseBasicParsing -ErrorAction SilentlyContinue) -replace '\s+', '' -replace '\n', '' +if (-not $externalIPv4) { $externalIPv4 = "Unavailable" } +if (-not $externalIPv6) { $externalIPv6 = "Unavailable" } + # Function to perform the URL and network tests function Test-Url { param ($url) $result = @{ Timestamp = (Get-Date).ToString("yyyy-MM-dd HH:mm:ss") # Explicitly convert to string format to avoid epoch time + Hostname = $hostname + OS = $osInfo + ExternalIPv4 = $externalIPv4 + ExternalIPv6 = $externalIPv6 Url = $url.Trim() StatusCode = "" ResponseTime = "" @@ -137,13 +149,14 @@ try { exit 1 } -# Send a notification to ntfy server with the Hastebin link and test settings +# Send a notification to ntfy server with the Hastebin link, hostname, OS info, and external IPs Write-Host "Sending notification to ntfy server..." try { - $ntfyMessage = "URL test completed. Log available at: $hasteLink`nTested URL: $url" + $ntfyMessage = "URL test completed on host: $hostname (OS: $osInfo, External IPv4: $externalIPv4, External IPv6: $externalIPv6). Log available at: $hasteLink`nTested URL: $url" $ntfyResponse = Invoke-RestMethod -Uri $ntfyServer -Method Post -Body $ntfyMessage -Headers @{ Authorization = "Basic $([Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes($ntfyCredentials)))" } Write-Host "Notification sent to ntfy." } catch { Write-Error "Failed to send notification to ntfy: $_" exit 1 } +