这个问题来自于试图管理我的家庭wifi网络.我一直在玩弄get-netipaddress,ipconfig和nslookup.exe等命令.
以下命令有点引导我,但它没有我正在寻找的信息.
Get-NetIPAddress | Format-Table
Run Code Online (Sandbox Code Playgroud)
我希望能够获得家庭网络上所有设备的列表.包括设备IP地址,以及该设备的某种名称.上一个命令给出了一个ipaddress,但它看起来更像是一个mac地址?任何帮助表示赞赏!
小智 9
我将我的批处理工具转换为Powershell脚本.
它是cmd行工具ping.exe,arp.exe和nslookup.exe的包装器.
为了获得良好的效果,应该打开并连接所有设备.
要将所有可能的DeviceIP放入计算机的arp缓存中,请
事先执行对假定/ 24子网中所有IP的ping操作.
Arp.exe -a将返回IP和MAC.Nslookup.exe用于查找从任何本地域后缀中删除的名称.
编辑var $ SubNet以适合您的环境.
## Q:\Test\2017\01\21\SO_41785413.ps1
$FileOut = ".\Computers.csv"
## Ping subnet
$Subnet = "192.168.xyz."
1..254|ForEach-Object{
Start-Process -WindowStyle Hidden ping.exe -Argumentlist "-n 1 -l 0 -f -i 2 -w 1 -4 $SubNet$_"
}
$Computers =(arp.exe -a | Select-String "$SubNet.*dynam") -replace ' +',','|
ConvertFrom-Csv -Header Computername,IPv4,MAC,x,Vendor|
Select Computername,IPv4,MAC
ForEach ($Computer in $Computers){
nslookup $Computer.IPv4|Select-String -Pattern "^Name:\s+([^\.]+).*$"|
ForEach-Object{
$Computer.Computername = $_.Matches.Groups[1].Value
}
}
$Computers
$Computers | Export-Csv $FileOut -NotypeInformation
#$Computers | Out-Gridview
Run Code Online (Sandbox Code Playgroud)
样本输出
Computername IPv4 MAC
------------ ---- ---
Zyxel-24G-Switch 192.168.xyz.1 fc-f5-28-fc-f5-28
TMDat1-Plex 192.168.xyz.60 02-7c-2c-02-7c-2c
HPn54L 192.168.xyz.91 c8-cb-b8-c8-cb-b8
Medion-Tablett 192.168.xyz.114 08-d8-33-08-d8-33
dLAN-LiveCam 192.168.xyz.115 bc-f2-af-bc-f2-af
McMini 192.168.xyz.128 40-6c-8f-40-6c-8f
HPojPro8500plus 192.168.xyz.144 d4-85-64-d4-85-64
Amazon-Kindle2 192.168.xyz.152 10-ae-60-10-ae-60
SG-S4-active 192.168.xyz.162 40-0e-85-40-0e-85
TMDat1 192.168.xyz.167 28-92-4a-28-92-4a
HP-G1610 192.168.xyz.176 10-60-4b-10-60-4b
NetStream4Sat 192.168.xyz.191 00-0c-6c-00-0c-6c
Netio230b 192.168.xyz.230 24-a4-2c-24-a4-2c
fritz 192.168.xyz.250 bc-05-43-bc-05-43
HomeMatic-CCU 192.168.xyz.254 00-1a-22-00-1a-22
Run Code Online (Sandbox Code Playgroud)
我自己的扩展版本附加了从Mac的前6个十六进制数字中提取的供应商,但需要从
" http://standards-oui.ieee.org/oui.txt " 下载非常慢的Oui.txt
| 归档时间: |
|
| 查看次数: |
18805 次 |
| 最近记录: |