Created
May 17, 2024 01:45
-
-
Save ShortArrow/020e9408fb79d138961152d74b13190b to your computer and use it in GitHub Desktop.
Search and listing hostnames from IPv4 with PowerShell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$network = "192.168.." | |
1..254 | ForEach-Object { | |
$ip = $network + $_ | |
$ping = Test-Connection -ComputerName $ip -Count 1 -Quiet | |
if ($ping) { | |
try { | |
$hostname = ([System.Net.Dns]::GetHostByAddress($ip)).HostName | |
} catch { | |
$hostname = $_.Exception.Message | |
} | |
Write-Output "$ip - $hostname" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment