1

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.

rationalboss
  • 5,330
  • 3
  • 30
  • 50
Imtyaz Ali
  • 11
  • 4

1 Answers1

3

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
ctacke
  • 66,480
  • 18
  • 94
  • 155
  • from "n" is giving ')' expected and 'intf' is not declared – Imtyaz Ali Sep 20 '12 at 13:56
  • If I pass like : MsgBox(GetAdapterForMac("00:19:70:7a:78:e0"))error showing "string cannot be converted to 'OpenNETCF.Net.NetworkInformation.PhysicalAddress" – Imtyaz Ali Sep 20 '12 at 16:03
  • 1
    PhysicalAddress.Parse is probably what you want, or the constructor that takes in a byte[]. I have no idea what your code is storing the address as. – ctacke Sep 20 '12 at 17:01
  • PhysicalAddress not having Parse method, how do i pass my MacAddress to Get IPAddress For selected mac address – Imtyaz Ali Sep 24 '12 at 06:37