From b6759748cae006bf1006bb5bc70d8c08b72580a7 Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Wed, 31 Jan 2024 10:53:05 +0100 Subject: [PATCH] Update ping-local-hosts.ps1 --- scripts/ping-local-hosts.ps1 | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/scripts/ping-local-hosts.ps1 b/scripts/ping-local-hosts.ps1 index 3545dbed..c1e03a34 100755 --- a/scripts/ping-local-hosts.ps1 +++ b/scripts/ping-local-hosts.ps1 @@ -5,24 +5,22 @@ This PowerShell script pings the computers in the local network and lists which one are up. .EXAMPLE PS> ./ping-local-hosts.ps1 - ✅ Up: Hippo Jenkins01 Jenkins02 Rocket Vega + ✅ Up: hippo jenkins01 jenkins02 rocket vega .LINK https://github.com/fleschutz/PowerShell .NOTES Author: Markus Fleschutz | License: CC0 #> +$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 +[int]$pingTimeout = 600 # ms + try { Write-Progress "Sending pings to the local hosts..." - [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 - $hostsArray = $hosts.Split(",") - $count = $hostsArray.Count - - [int]$timeout = 600 # ms $queue = [System.Collections.Queue]::new() foreach($hostname in $hostsArray) { $ping = [System.Net.Networkinformation.Ping]::new() - $obj = @{ Host = $hostname; Ping = $ping; Async = $ping.SendPingAsync($hostname, $timeout) } + $obj = @{ Host = $hostname; Ping = $ping; Async = $ping.SendPingAsync($hostname, $pingTimeout) } $queue.Enqueue($obj) } @@ -30,7 +28,7 @@ try { while ($queue.Count -gt 0) { $obj = $queue.Dequeue() try { - if ($obj.Async.Wait($timeout) -eq $true) { + if ($obj.Async.Wait($pingTimeout) -eq $true) { if ($obj.Async.Result.Status -ne "TimedOut") { $result += "$($obj.Host) " }