Skip to content

Commit d67cf22

Browse files
committed
BornToBeRoot#50 OUI list changed from txt to xml
1 parent 77dd54b commit d67cf22

5 files changed

Lines changed: 95481 additions & 17 deletions

File tree

Scripts/Create-OUIListFromWeb.ps1

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,46 @@
1-
#$LatestOUI = Get-Content -Path "$PSScriptRoot\oui_from_web.txt"
1+
# Filepath in the resources...
2+
[string]$OutFilePath = Join-Path -Path (Split-Path $PSScriptRoot -Parent) -ChildPath "Source\NETworkManager\Resources\OUI.xml"
3+
4+
# Download cleanup IEEE oui version from linuxnet
25
$LatestOUIs = (Invoke-WebRequest -Uri "http://linuxnet.ca/ieee/oui.txt").Content
36

4-
$Output = ""
7+
# Create xml document
8+
[xml]$Document = New-Object System.Xml.XmlDocument
9+
$Declaration = $Document.CreateXmlDeclaration("1.0", "UTF-8", $null)
10+
11+
[void]$Document.AppendChild($Declaration)
12+
13+
# Description
14+
$Description = @"
15+
Organizationally unique identifier
16+
Generated $(Get-Date)
17+
"@
18+
19+
[void]$Document.AppendChild($Document.CreateComment($Description))
20+
21+
# Root node
22+
$RootNode = $Document.CreateNode("element", "OUIs", $null)
523

624
foreach($Line in $LatestOUIs -split '[\r\n]')
725
{
826
if($Line -match "^[A-F0-9]{6}")
9-
{
27+
{
1028
# Line looks like: 2405F5 (base 16) Integrated Device Technology (Malaysia) Sdn. Bhd.
11-
$Output += ($Line -replace '\s+', ' ').Replace(' (base 16) ', '|').Trim() + "`n"
29+
$OUIData = ($Line -replace '\s+', ' ').Replace(' (base 16) ', '|').Trim().Split('|')
30+
31+
$OUINode = $Document.CreateNode("element", "OUI", $null)
32+
33+
$MACAddressElement = $Document.CreateElement("MACAddress")
34+
$MACAddressElement.InnerText = $OUIData[0]
35+
[void]$OUINode.AppendChild($MACAddressElement)
36+
37+
$VendorElement = $Document.CreateElement("Vendor")
38+
$VendorElement.InnerText = $OUIData[1]
39+
[void]$OUINode.AppendChild($VendorElement)
40+
41+
[void]$RootNode.AppendChild($OUINode)
1242
}
1343
}
1444

15-
Out-File -InputObject $Output -FilePath (Join-Path -Path (Split-Path $PSScriptRoot -Parent) -ChildPath "Source\NETworkManager\Resources\oui.txt")
45+
[void]$Document.AppendChild($RootNode)
46+
$Document.Save($OutFilePath)

Source/NETworkManager/Models/Network/OUILookup.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
using System.Text.RegularExpressions;
77
using System;
88
using System.Windows;
9+
using System.Xml;
910

1011
namespace NETworkManager.Models.Network
1112
{
1213
public static class OUILookup
1314
{
1415
#region Variables
15-
private static string OUIFilePath = Path.Combine(ConfigurationManager.Current.ExecutionPath, "Resources", "oui.txt");
16+
private static string OUIFilePath = Path.Combine(ConfigurationManager.Current.ExecutionPath, "Resources", "OUI.xml");
1617

1718
private static List<OUIInfo> OUIList;
1819
private static Lookup<string, OUIInfo> OUIs;
@@ -23,15 +24,12 @@ static OUILookup()
2324
{
2425
OUIList = new List<OUIInfo>();
2526

26-
// Load list from resource folder (.txt-file)
27-
foreach (string line in File.ReadAllLines(OUIFilePath))
28-
{
29-
if (string.IsNullOrEmpty(line))
30-
continue;
31-
32-
string[] ouiData = line.Split('|');
27+
XmlDocument document = new XmlDocument();
28+
document.Load(OUIFilePath);
3329

34-
OUIList.Add(new OUIInfo(ouiData[0], ouiData[1]));
30+
foreach(XmlNode node in document.SelectNodes("/OUIs/OUI"))
31+
{
32+
OUIList.Add(new OUIInfo(node.SelectSingleNode("MACAddress").InnerText, node.SelectSingleNode("Vendor").InnerText));
3533
}
3634

3735
OUIs = (Lookup<string, OUIInfo>)OUIList.ToLookup(x => x.MACAddress);

Source/NETworkManager/NETworkManager.csproj

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -648,9 +648,6 @@
648648
</ItemGroup>
649649
<ItemGroup>
650650
<Resource Include="Resources\Entypo.ttf" />
651-
<None Include="Resources\oui.txt">
652-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
653-
</None>
654651
</ItemGroup>
655652
<ItemGroup>
656653
<Resource Include="3rdParty\Heijden.DNS\Records\totla.txt" />
@@ -667,6 +664,11 @@
667664
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
668665
</None>
669666
</ItemGroup>
667+
<ItemGroup>
668+
<None Include="Resources\OUI.xml">
669+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
670+
</None>
671+
</ItemGroup>
670672
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
671673
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
672674
Other similar extension points exist, see Microsoft.Common.targets.

0 commit comments

Comments
 (0)