0

我有这个片段,它是在 Java 中的:

final InetAddress address = InetAddress.getLocalHost();
final NetworkInterface ni = NetworkInterface.getByInetAddress(address);
key = new String(ni.getHardwareAddress());

键输出示例:▲╔UiÎ

VB.Net 中的等价物是什么?我知道第一行获取本地主机,其余的呢?提前致谢。

4

1 回答 1

1

这会遍历所有本地接口:

Dim theNetworkInterfaces() as System.Net.NetworkInformation.NetworkInterface = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()

for each curInterface as System.Net.NetworkInformation.NetworkInterface in theNetworkInterfaces

   MessageBox.Show(curInterface.GetPhysicalAddress().ToString())

物理地址就是你想要的。

线

final NetworkInterface ni = NetworkInterface.getByInetAddress(address);

只需通过 inetaddress 获取特定的网络接口假设您将 localhost 地址存储在名为 localIa 的变量中,然后您可以使用它:

NetworkInterface ni = NetworkInterface.getByInetAddress(localIa)
ni.GetPhysicalAddress().ToString()
于 2011-01-28T18:45:14.453 回答