Commit 175099a5 authored by Brickner_cp's avatar Brickner_cp

GetMacAddress() of a LivePacketDevice

parent 661af464
using System;
using System.Net.NetworkInformation;
using PcapDotNet.Base;
using PcapDotNet.Packets;
using PcapDotNet.Packets.Ethernet;
namespace PcapDotNet.Core.Extensions
{
public static class LivePacketDeviceExtensions
{
public static NetworkInterface GetNetworkInterface(this LivePacketDevice livePacketDevice)
{
foreach (NetworkInterface networkInterface in NetworkInterface.GetAllNetworkInterfaces())
{
if (@"rpcap://\Device\NPF_" + networkInterface.Id == livePacketDevice.Name)
return networkInterface;
}
return null;
}
public static MacAddress GetMacAddress(this LivePacketDevice livePacketDevice)
{
NetworkInterface networkInterface = livePacketDevice.GetNetworkInterface();
if (networkInterface == null)
throw new InvalidOperationException("Couldn't find a network interface for give device");
byte[] addressBytes = networkInterface.GetPhysicalAddress().GetAddressBytes();
return new MacAddress(addressBytes.ReadUInt48(0, Endianity.Big));
}
}
}
\ No newline at end of file
......@@ -10,7 +10,7 @@ namespace PcapDotNet.Core.Extensions
/// Different extension methods for PacketCommunicator class.
/// <seealso cref="PacketCommunicator"/>
/// </summary>
public static class MorePacketCommunicator
public static class PacketCommunicatorExtensions
{
/// <summary>
/// Collect a group of packets.
......
......@@ -3,7 +3,7 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.21022</ProductVersion>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{322040C2-3DC1-4D0C-8E0F-F05290AFE023}</ProjectGuid>
<OutputType>Library</OutputType>
......@@ -55,10 +55,15 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="MorePacketCommunicator.cs" />
<Compile Include="LivePacketDeviceExtensions.cs" />
<Compile Include="PacketCommunicatorExtensions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PcapDotNet.Base\PcapDotNet.Base.csproj">
<Project>{83E805C9-4D29-4E34-A27E-5A78690FBD2B}</Project>
<Name>PcapDotNet.Base</Name>
</ProjectReference>
<ProjectReference Include="..\PcapDotNet.Core\PcapDotNet.Core.vcproj">
<Project>{89C63BE1-AF9A-472E-B256-A4F56B1655A7}</Project>
<Name>PcapDotNet.Core</Name>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment