Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Scripts/Create-OUIListFromWeb.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#$LatestOUI = Get-Content -Path "$PSScriptRoot\oui_from_web.txt"
$LatestOUI = (Invoke-WebRequest -Uri "http://linuxnet.ca/ieee/oui.txt").Content

$Output = ""

foreach($Line in $LatestOUI -split '[\r\n]')
{
if($Line -match "^[A-F0-9]{6}")
{
# Line looks like: 2405F5 (base 16) Integrated Device Technology (Malaysia) Sdn. Bhd.
$Output += ($Line -replace '\s+', ' ').Replace(' (base 16) ', '|').Trim() + "`n"
}
}

Out-File -InputObject $Output -FilePath (Join-Path -Path (Split-Path $PSScriptRoot -Parent) -ChildPath "Source\NETworkManager\Resources\oui.txt")
11 changes: 6 additions & 5 deletions Source/NETworkManager/Converters/IPAddressToStringConverter.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
using System;
using System.Globalization;
using System.Net;
using System.Windows.Data;

namespace NETworkManager.Converters
{
public sealed class IPAddressToStringConverter : IValueConverter
public sealed class NullOrEmptyToStringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null)
string str = value as string;

if (string.IsNullOrEmpty(str))
return "-/-";
return ((IPAddress)value).ToString();

return str;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
Expand Down
23 changes: 23 additions & 0 deletions Source/NETworkManager/Converters/NullOrEmptyToStringConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Globalization;
using System.Net;
using System.Windows.Data;

namespace NETworkManager.Converters
{
public sealed class IPAddressToStringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null)
return "-/-";

return ((IPAddress)value).ToString();
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
1 change: 1 addition & 0 deletions Source/NETworkManager/Helpers/RegexHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public static class RegexHelper

// Match a MAC-Address 00-00-00-00-00-00-00
public const string MACAddressRegex = @"^[A-Fa-f0-9]{12}$|^[A-Fa-f0-9]{2}(:|-){1}[A-Fa-f0-9]{2}(:|-){1}[A-Fa-f0-9]{2}(:|-){1}[A-Fa-f0-9]{2}(:|-){1}[A-Fa-f0-9]{2}(:|-){1}[A-Fa-f0-9]{2}$";
public const string MACAddressFirst3BytesRegex = @"^[A-Fa-f0-9]{6}$|^[A-Fa-f0-9]{2}(:|-){1}[A-Fa-f0-9]{2}(:|-){1}[A-Fa-f0-9]{2}$";

// Match a Subnetmask like 255.255.255.0
private const string SubnetmaskValues = @"(255|254|252|248|240|224|192|128|0)";
Expand Down
2 changes: 1 addition & 1 deletion Source/NETworkManager/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@
</Rectangle>
<TextBlock Grid.Column="1" Text="{Binding TranslatedName}">
<TextBlock.Style>
<Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource DefaultTextBlockStyle}">
<Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource HeaderTextBlock}">
<Setter Property="Foreground" Value="{DynamicResource GrayBrush3}" />
<Setter Property="Margin" Value="0" />
<Setter Property="VerticalAlignment" Value="Center" />
Expand Down
17 changes: 12 additions & 5 deletions Source/NETworkManager/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public MainWindow()

// Load templates
TemplateManager.LoadNetworkInterfaceConfigTemplates();
TemplateManager.LoadWakeOnLanTemplates();
TemplateManager.LoadWakeOnLANTemplates();

_isLoading = false;
}
Expand Down Expand Up @@ -244,9 +244,9 @@ private async void MetroWindowMain_Closing(object sender, CancelEventArgs e)
// Save templates
if (TemplateManager.NetworkInterfaceConfigTemplatesChanged && !ImportExportManager.ForceRestart)
TemplateManager.SaveNetworkInterfaceConfigTemplates();
if (TemplateManager.WakeOnLanTemplatesChanged && !ImportExportManager.ForceRestart)
TemplateManager.SaveWakeOnLanTemplates();

if (TemplateManager.WakeOnLANTemplatesChanged && !ImportExportManager.ForceRestart)
TemplateManager.SaveWakeOnLANTemplates();

// Save settings
if (SettingsManager.Current.SettingsChanged && !ImportExportManager.ForceRestart)
Expand All @@ -271,6 +271,7 @@ private async void MetroWindowMain_Closing(object sender, CancelEventArgs e)
PingView pingView;
TracerouteView tracerouteView;
DNSLookupView dnsLookupView;
OUILookupView ouiLookupView;

private ApplicationView.Name? currentApplicationViewName = null;

Expand Down Expand Up @@ -329,6 +330,12 @@ private void ChangeApplicationView(ApplicationView.Name name)

contentControlApplication.Content = dnsLookupView;
break;
case ApplicationView.Name.OUILookup:
if (ouiLookupView == null)
ouiLookupView = new OUILookupView();

contentControlApplication.Content = ouiLookupView;
break;
}

currentApplicationViewName = name;
Expand Down Expand Up @@ -614,7 +621,7 @@ private void CloseApplicationAction()

private void RestartApplication()
{
Process.Start(Assembly.GetExecutingAssembly().Location);
Process.Start(ConfigurationManager.Current.ApplicationPath);

_closeApplication = true;
Close();
Expand Down
9 changes: 7 additions & 2 deletions Source/NETworkManager/Models/Network/IPScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,25 @@ public void ScanAsync(IPAddress[] ipAddresses, IPScannerOptions ipScannerOptions

// ARP
PhysicalAddress macAddress = null;
string vendor = string.Empty;

if (ipScannerOptions.ResolveMACAddress)
{
try
{
// Get mac
if (Dns.GetHostName() == hostname.Substring(0, hostname.IndexOf('.')))
macAddress = NetworkInterface.GetNetworkInterfaces().Where(p => p.IPv4Address.Contains(ipAddress)).FirstOrDefault().PhysicalAddress;
macAddress = NetworkInterface.GetNetworkInterfaces().Where(p => p.IPv4Address.Contains(ipAddress)).First().PhysicalAddress;
else
macAddress = IPNetTableHelper.GetAllDevicesOnLAN().Where(p => p.Key.ToString() == ipAddress.ToString()).ToDictionary(p => p.Key, p => p.Value).First().Value;

// Vendor lookup
vendor = OUILookup.Lookup(macAddress).Vendor;
}
catch { }
}

OnHostFound(new IPScannerHostFoundArgs(pingInfo, hostname, macAddress));
OnHostFound(new IPScannerHostFoundArgs(pingInfo, hostname, macAddress, vendor));

break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ public class IPScannerHostFoundArgs : System.EventArgs
public PingInfo PingInfo { get; set; }
public string Hostname { get; set; }
public PhysicalAddress MACAddress { get; set; }
public string Vendor { get; set; }

public IPScannerHostFoundArgs()
{

}

public IPScannerHostFoundArgs(PingInfo pingInfo, string hostname, PhysicalAddress macAddress)
public IPScannerHostFoundArgs(PingInfo pingInfo, string hostname, PhysicalAddress macAddress, string vendor)
{
PingInfo = pingInfo;
Hostname = hostname;
MACAddress = macAddress;
}
Vendor = vendor;
}
}
}
11 changes: 6 additions & 5 deletions Source/NETworkManager/Models/Network/IPScannerHostInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

using System.Net.NetworkInformation;
using System.Net.NetworkInformation;

namespace NETworkManager.Models.Network
{
Expand All @@ -8,22 +7,24 @@ public class IPScannerHostInfo
public PingInfo PingInfo { get; set; }
public string Hostname { get; set; }
public PhysicalAddress MACAddress { get; set; }
public string Vendor { get; set; }

public IPScannerHostInfo()
{

}

public IPScannerHostInfo(PingInfo pingInfo, string hostname, PhysicalAddress macAddress)
public IPScannerHostInfo(PingInfo pingInfo, string hostname, PhysicalAddress macAddress, string vendor)
{
PingInfo = pingInfo;
Hostname = hostname;
MACAddress = macAddress;
Vendor = vendor;
}

public static IPScannerHostInfo Parse(IPScannerHostFoundArgs e)
{
return new IPScannerHostInfo(e.PingInfo, e.Hostname, e.MACAddress);
return new IPScannerHostInfo(e.PingInfo, e.Hostname, e.MACAddress, e.Vendor);
}
}
}
19 changes: 19 additions & 0 deletions Source/NETworkManager/Models/Network/OUIInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace NETworkManager.Models.Network
{
public class OUIInfo
{
public string MACAddress { get; set; }
public string Vendor { get; set; }

public OUIInfo()
{

}

public OUIInfo(string macAddress, string vendor)
{
MACAddress = macAddress;
Vendor = vendor;
}
}
}
59 changes: 59 additions & 0 deletions Source/NETworkManager/Models/Network/OUILookup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.IO;
using NETworkManager.Models.Settings;
using System.Text.RegularExpressions;
using System.Net.NetworkInformation;

namespace NETworkManager.Models.Network
{
public static class OUILookup
{
#region Variables
private static string OUIPath = Path.Combine(ConfigurationManager.Current.StartupPath, "Resources", "oui.txt");

public static Dictionary<string, string> OUIDict = new Dictionary<string, string>();

#endregion

#region Methods
static OUILookup()
{
// Load list from resource folder (.txt-file)
foreach (string line in File.ReadAllLines(OUIPath))
{
string[] ouiData = line.Split('|');

if (!string.IsNullOrEmpty(ouiData[0]) && !OUIDict.Keys.Contains(ouiData[0]))
OUIDict.Add(ouiData[0], ouiData[1]);
}
}

public static Task<OUIInfo> LookupAsync(string macAddressOrFirst3Bytes)
{
return Task.Run(() => Lookup(macAddressOrFirst3Bytes));
}

public static OUIInfo Lookup(string macAddressOrFirst3Bytes)
{
string ouiKey = Regex.Replace(macAddressOrFirst3Bytes, "-|:", "").Substring(0,6);

string vendor = string.Empty;
OUIDict.TryGetValue(ouiKey, out vendor);

return new OUIInfo(ouiKey, vendor);
}

public static Task<OUIInfo> LookupAsync(PhysicalAddress macAddress)
{
return Task.Run(() => Lookup(macAddress));
}

public static OUIInfo Lookup(PhysicalAddress macAddress)
{
return Lookup(macAddress.ToString());
}
#endregion
}
}
7 changes: 3 additions & 4 deletions Source/NETworkManager/Models/Network/Ping.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

using System;
using System;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
Expand All @@ -22,14 +21,14 @@ protected virtual void OnPingReceived(PingArgs e)

protected virtual void OnPingCompleted()
{
PingCompleted?.Invoke(this, System.EventArgs.Empty);
PingCompleted?.Invoke(this, EventArgs.Empty);
}

public event EventHandler UserHasCanceled;

protected virtual void OnUserHasCanceled()
{
UserHasCanceled?.Invoke(this, System.EventArgs.Empty);
UserHasCanceled?.Invoke(this, EventArgs.Empty);
}

public void SendAsync(IPAddress ipAddress, PingOptions pingOptions, CancellationToken cancellationToken)
Expand Down
4 changes: 2 additions & 2 deletions Source/NETworkManager/Models/Network/WakeOnLan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace NETworkManager.Models.Network
{
public class WakeOnLan
public class WakeOnLAN
{
#region Events
public event EventHandler Completed;
Expand All @@ -15,7 +15,7 @@ protected virtual void OnCompleted()
#endregion

#region Methods
public void Send(WakeOnLanInfo info)
public void Send(WakeOnLANInfo info)
{
using (UdpClient udpClient = new UdpClient())
{
Expand Down
6 changes: 3 additions & 3 deletions Source/NETworkManager/Models/Network/WakeOnLanInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

namespace NETworkManager.Models.Network
{
public class WakeOnLanInfo
public class WakeOnLANInfo
{
public byte[] MagicPacket;
public IPAddress Broadcast;
public int Port;

public WakeOnLanInfo()
public WakeOnLANInfo()
{

}

public WakeOnLanInfo(byte[] magicPacket, IPAddress broadcast, int port)
public WakeOnLANInfo(byte[] magicPacket, IPAddress broadcast, int port)
{
MagicPacket = magicPacket;
Broadcast = broadcast;
Expand Down
4 changes: 3 additions & 1 deletion Source/NETworkManager/Models/Settings/ConfigurationInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
public class ConfigurationInfo
{
public bool IsAdmin { get; set; }

public string StartupPath { get; set; }
public string ApplicationPath { get; set; }

public ConfigurationInfo()
{

Expand Down
11 changes: 9 additions & 2 deletions Source/NETworkManager/Models/Settings/ConfigurationManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System.Security.Principal;
using System.Reflection;
using System.Security.Principal;
using System.IO;

namespace NETworkManager.Models.Settings
{
public static class ConfigurationManager
Expand All @@ -7,9 +10,13 @@ public static class ConfigurationManager

public static void Detect()
{
string applicationLocation = Assembly.GetExecutingAssembly().Location;

Current = new ConfigurationInfo()
{
IsAdmin = (new WindowsPrincipal(WindowsIdentity.GetCurrent())).IsInRole(WindowsBuiltInRole.Administrator)
IsAdmin = (new WindowsPrincipal(WindowsIdentity.GetCurrent())).IsInRole(WindowsBuiltInRole.Administrator),
StartupPath = Path.GetDirectoryName(applicationLocation),
ApplicationPath = Path.GetFileName(applicationLocation)
};
}
}
Expand Down
Loading