我有获取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
由于
答案 0 :(得分:0)
沿着这些方向做的事情就是这样:
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());
}