Windows Parity

This commit is contained in:
Colin 2024-08-29 17:10:10 -04:00
parent 93b20128f5
commit a07fe07605
1 changed files with 15 additions and 2 deletions

View File

@ -13,11 +13,23 @@ $hastebinUrl = "https://haste.nixc.us/documents"
$ntfyServer = "https://ntfy.nixc.us/bnHobG80sO5ZF4SB" $ntfyServer = "https://ntfy.nixc.us/bnHobG80sO5ZF4SB"
$ntfyCredentials = "admin:tiZcgc8Waf9mg5A4n2aJ4Qk2RyYnwEHDT" $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 to perform the URL and network tests
function Test-Url { function Test-Url {
param ($url) param ($url)
$result = @{ $result = @{
Timestamp = (Get-Date).ToString("yyyy-MM-dd HH:mm:ss") # Explicitly convert to string format to avoid epoch time 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() Url = $url.Trim()
StatusCode = "" StatusCode = ""
ResponseTime = "" ResponseTime = ""
@ -137,13 +149,14 @@ try {
exit 1 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..." Write-Host "Sending notification to ntfy server..."
try { 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)))" } $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." Write-Host "Notification sent to ntfy."
} catch { } catch {
Write-Error "Failed to send notification to ntfy: $_" Write-Error "Failed to send notification to ntfy: $_"
exit 1 exit 1
} }