开发者

Java to VB.Net Conversion [Small Snippet]

开发者 https://www.devze.com 2023-02-07 02:30 出处:网络
I have this snippet, it\'s in Java: final InetAddress address = InetAddress.getLocalHost(); final NetworkInterface ni = NetworkInterface.getByInetAddress(ad开发者_JAVA百科dress);

I have this snippet, it's in Java:

final InetAddress address = InetAddress.getLocalHost();
final NetworkInterface ni = NetworkInterface.getByInetAddress(ad开发者_JAVA百科dress);
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.


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号