Skip to content

Instantly share code, notes, and snippets.

@ShortArrow
Created May 17, 2024 01:45
Show Gist options
  • Select an option

  • Save ShortArrow/020e9408fb79d138961152d74b13190b to your computer and use it in GitHub Desktop.

Select an option

Save ShortArrow/020e9408fb79d138961152d74b13190b to your computer and use it in GitHub Desktop.

Revisions

  1. ShortArrow created this gist May 17, 2024.
    13 changes: 13 additions & 0 deletions serch_n_list_hostname_by_ip.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    $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"
    }
    }