-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPinger.ps1
More file actions
35 lines (30 loc) · 735 Bytes
/
Copy pathPinger.ps1
File metadata and controls
35 lines (30 loc) · 735 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#logging
$logFile = "PingLogs.txt"
function Log-Message {
param (
[string]$message
)
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
$logEntry = "$timestamp - $message"
Write-Output $logEntry
Add-Content -Path $logFile -Value $logEntry
}
# pass in host to test
function Ping-Host {
param (
[string]$targetHost
)
$pingResult = Test-Connection -ComputerName $targetHost -Count 1 -Quiet
if (-not $pingResult) {
Log-Message "Connection to $targetHost lost."
}
else {
#Write-Output $pingResult
}
}
# Main
while ($true) {
Ping-Host -targetHost "192.168.1.2" #Router/Firewall
Ping-Host -targetHost "google.com"
Start-Sleep -Seconds 15
}