This project is read-only.

How to retrieve the MAC Address of a LivePacketDevice?

Jan 28, 2010 at 5:45 PM

Hi,

I cannot find a way to determine the MAC address of an Ethernet network adapter represented by a LivePacketDevice. The only solution I can think of is reading  the IP address and using .NETs built-in classes to find the corresponding Network Adapter and it's MAC Address. But LivePacketDevice.Addresses seems to be empty for one of my adaptors, although I've configured an IP address.

 

Also it would be nice to get a LivePacketDevice's MAC when theres no IP-Protocol configured at all.

 

Do I miss anything?

 

Thanks,

Philipp

Jan 29, 2010 at 2:26 PM

Hi Philipp,

 

You're not missing anything.

LivePacketDevice doesn't have a MacAddress property since winpcap doesn't support this.

Since Pcap.Net is a winpcap wrapper, it exports winpcap features and everything else are additions to winpcap's API.

 

However, since you've requested this, I've added support for getting the MacAddress from a LivePacketDevice.

I've added an extension method for LivePacketDevice called GetMacAddress().

It is in PcapDotNet.Core.Extensions dll and it uses .NET's NetworkInterface class.

I believe it should work (it works fine on my machine) and I hope it won't be too platform specific.

 

In order to use it you should do one of the following:

1. Wait for the next version of Pcap.Net.

2. Download the updated sources, compile and use it for yourself (recommended).

3. Use .NET's NetworkInterface class for yourself.

 

I hope this helps you.

 

Boaz.

Jan 29, 2010 at 3:00 PM

Thanks alot!

I was about to parse the LivePacketDevice's Name for its guid to find the corresponding NetworkInterface by myself, but this definitely makes things easier :-)

 

Mar 12, 2010 at 8:45 AM

Pcap.Net version 0.5.0 was released today.

This version added the GetMacAddress() extension method of LivePacketDevice.

May 12, 2015 at 7:19 PM
Sir brickner... Kindly tell me how to use GetMacAddress()?
May 16, 2015 at 12:04 PM
Hi RaheelShehzad,

If you have a LivePacketDevice, you can use

LivePacketDeviceExtensions.GetMacAddress(myLivePacketDevice);

Alternatively, since this is an extension method, you can write

myLivePacketDevice.GetMacAddress();

I hope this helps,

Boaz.