Skip to content

Commit b675974

Browse files
committed
Update ping-local-hosts.ps1
1 parent 8fcdf14 commit b675974

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

scripts/ping-local-hosts.ps1

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,30 @@
55
This PowerShell script pings the computers in the local network and lists which one are up.
66
.EXAMPLE
77
PS> ./ping-local-hosts.ps1
8-
✅ Up: Hippo Jenkins01 Jenkins02 Rocket Vega
8+
✅ Up: hippo jenkins01 jenkins02 rocket vega
99
.LINK
1010
https://github.com/fleschutz/PowerShell
1111
.NOTES
1212
Author: Markus Fleschutz | License: CC0
1313
#>
1414

15+
$hostsArray = @('amnesiac','archlinux','berlin','boston','brother','canon','castor','cisco','echodot','epson','fedora','fireball','firewall','fritz.box','gassensor','gateway','hippo','heizung','homemanager','io','iphone','jarvis','jenkins','la','laptop','jupiter','mars','mercury','miami','mobile','ny','octopi','office','officepc','paris','pi','pixel-6a','pluto','printer','proxy','r2d2','raspberry','rocket','rome','router','server','shelly1','smartphone','smartwatch','soundbar','sunnyboy','surface','switch','tablet','tau','tolino','tv','ubuntu','vega','venus','xrx','zeus') # sorted alphabetically
16+
[int]$pingTimeout = 600 # ms
17+
1518
try {
1619
Write-Progress "Sending pings to the local hosts..."
17-
[string]$hosts = "Amnesiac,ArchLinux,Berlin,Boston,Brother,Canon,Castor,Cisco,EchoDot,Epson,Fedora,Fireball,Firewall,fritz.box,GasSensor,Gateway,Hippo,HomeManager,Io,iPhone,Jarvis,Jenkins01,Jenkins02,LA,Laptop,Jupiter,Mars,Mercury,Miami,Mobile,NY,OctoPi,Paris,Pixel-6a,Pluto,Printer,Proxy,R2D2,Raspberry,Rocket,Rome,Router,Server,Shelly1,SmartPhone,SmartWatch,Soundbar,Sunnyboy,Surface,Switch,Tablet,Tolino,TV,Ubuntu,Vega,Venus,XRX,Zeus" # sorted alphabetically
18-
$hostsArray = $hosts.Split(",")
19-
$count = $hostsArray.Count
20-
21-
[int]$timeout = 600 # ms
2220
$queue = [System.Collections.Queue]::new()
2321
foreach($hostname in $hostsArray) {
2422
$ping = [System.Net.Networkinformation.Ping]::new()
25-
$obj = @{ Host = $hostname; Ping = $ping; Async = $ping.SendPingAsync($hostname, $timeout) }
23+
$obj = @{ Host = $hostname; Ping = $ping; Async = $ping.SendPingAsync($hostname, $pingTimeout) }
2624
$queue.Enqueue($obj)
2725
}
2826

2927
[string]$result = ""
3028
while ($queue.Count -gt 0) {
3129
$obj = $queue.Dequeue()
3230
try {
33-
if ($obj.Async.Wait($timeout) -eq $true) {
31+
if ($obj.Async.Wait($pingTimeout) -eq $true) {
3432
if ($obj.Async.Result.Status -ne "TimedOut") {
3533
$result += "$($obj.Host) "
3634
}

0 commit comments

Comments
 (0)