PowerShell 技能连载 - 获取 MAC 制造商列表

Prateek Singh 贡献了一个干净的,CSV 格式的的 MAC 厂商列表。这个列表可以在他的博客 Get-MACVendor using Powershell – Geekeefy 找到。在通过 MAC 地址确定网络设备的厂商时,这个列表十分有用。

您可以用 PowerShell 方便地将它下载到计算机中:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#requires -Version 3.0

$url = 'http://goo.gl/VG9XdU'
$target = "$home\Documents\macvendor.csv"
Invoke-WebRequest -Uri $url -UseBasicParsing -OutFile $target

$content = Import-Csv -Path $target
$content | Out-GridView


With this awesome list, you can now take the first three numbers of any MAC address and find its manufacturer. Here is a simple sample implementation taking the information from Get-NetAdapter, and adding Manufacturer info:

#requires -Modules NetAdapter
#requires -Version 4.0

$url = 'https://raw.githubusercontent.com/PrateekKumarSingh/PowershellScrapy/master/MACManufacturers/MAC_Manufacturer_Reference.csv'
$target = "$home\Documents\macvendor.csv"
$exists = Test-Path -Path $target
if (!$exists)
{
Invoke-WebRequest -Uri $url -UseBasicParsing -OutFile $target
}

$content = Import-Csv -Path $target

Get-NetAdapter |
ForEach-Object {
$macString = $_.MacAddress.SubString(0, 8).Replace('-','')
$manufacturer = $content.
Where{$_.Assignment -like "*$macString*"}.
Foreach{$_.ManufacturerName}

$_ |
Add-Member -MemberType NoteProperty -Name Manufacturer -Value $manufacturer[0] -PassThru |
Select-Object -Property Name, Mac*, Manufacturer
}

本文国际来源:Getting MAC Vendor List

评论