Java 到 VB.Net 的转换 [小片段]

发布于 2024-10-14 22:58:06 字数 294 浏览 7 评论 0原文

我有这个片段,它是用 Java 编写的:

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

关键输出示例:▲╔UiÎ

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

I have this snippet, it's in Java:

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

Example of key output: ▲╔UiÎ

What is the equivalent in VB.Net? I understand the first line gets Local Host, what about the rest? Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云巢 2024-10-21 22:58:06

这会迭代所有本地接口:

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 获取特定的网络接口
假设您将本地主机地址存储在名为 localIa 的变量中,然后您可以使用它:

NetworkInterface ni = NetworkInterface.getByInetAddress(localIa)
ni.GetPhysicalAddress().ToString()

This iterates over all local interfaces:

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())

The physical address is what you want.

The line

final NetworkInterface ni = NetworkInterface.getByInetAddress(address);

just grabs the specific network interface by the inetaddress
Say you store your localhost address in a variable called localIa and then you can use it:

NetworkInterface ni = NetworkInterface.getByInetAddress(localIa)
ni.GetPhysicalAddress().ToString()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文