0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

windowsから同一ネットワークのデバイス名一覧を取得するコマンド

Posted at

やること

windowsから192.168.0.0/24 ネットワークに接続しているローカルホスト名(デバイス名)を取得するコマンドです
powersheellで実行してください。

# スキャン範囲の設定
$networkPrefix = "192.168.0."

# 1〜254までのIPアドレス範囲をループ
1..254 | ForEach-Object {
    $ip = "$networkPrefix$_"
    
    # デバイスに ping を送信
    $pingResult = Test-Connection -ComputerName $ip -Count 1 -Quiet
    
    if ($pingResult) {
        try {
            # 名前解決を行い、IPアドレスとホスト名を取得
            $hostEntry = [System.Net.Dns]::GetHostEntry($ip)
            $hostName = $hostEntry.HostName
            Write-Output "$ip - $hostName"
        } catch {
            # 名前解決できなかった場合
            Write-Output "$ip - Hostname not found"
        }
    } else {
        Write-Output "$ip - No Response"
    }
}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?