Imtyaz Ali
Imtyaz Ali

Reputation: 11

Get IP address from Mac ID in WindowsCE

How do I find the IP Address for a mac id in WindowsCE using VB.net Smartdevice application in VS 2008/ VS2005?

I am trying to use OpenNETCF.Net but I am not getting the desired results.

Does anyone know this? Please post your suggestions.

Upvotes: 1

Views: 1614

Answers (1)

ctacke
ctacke

Reputation: 67188

You say you tried using the OpenNETCF.Net.dll assembly, but you didn't say what you tried. In C# it would look something like this:

IPAddress GetAdapterForMac(PhysicalAddress mac)
{
    var intf = (from n in NetworkInterface.GetAllNetworkInterfaces()
            where n.GetPhysicalAddress().Equals(mac)
            select n).FirstOrDefault();

    if (intf == null) return null;

    return intf.CurrentIpAddress;
}

My VB.NET is rusty, but I think that translates to something like this:

Imports System.Linq
Imports OpenNETCF.Net.NetworkInformation

Private Function GetAdapterForMac(mac As PhysicalAddress) As IPAddress
    Dim intf as NetworkInterface = (From n In NetworkInterface.GetAllNetworkInterfaces() _
              Where n.GetPhysicalAddress().Equals(mac) _
              Select n).FirstOrDefault()

    If intf Is Nothing
        Return Nothing
    End If

    Return intf.CurrentIpAddress
End Function

Upvotes: 3

Related Questions