0

我有将 Mac 地址获取到 IPAddress 的示例代码,我正在尝试调用该函数,但我没有得到。

我有 Mac 地址

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim macadd As String = "00:19:70:7a:78:e0"

    '' HOW DO I CONVERT STRING VALUE TO PHYSICALADDRESS OBJECT, because Physical.Parse i not available

    ''MsgBox(GetAdapterForMac(macaddress)) '' I want to Pass mac address here
End Sub



Private Function GetAdapterForMac(ByVal 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 Then
        Return Nothing
    End If
    Return intf.CurrentIpAddress()
End Function

谢谢

4

1 回答 1

0

Something along these lines will do it:

public static PhysicalAddress Parse(string data)
{
    var bytes = new List<byte>();
    foreach(var b in data.Split(':'))
    {
        bytes.Add(byte.Parse(b, System.Globalization.NumberStyles.HexNumber));
    };
    return new PhysicalAddress(bytes.ToArray());
}
于 2012-10-20T01:43:27.510 回答