简体   繁体   中英

Java to VB.Net Conversion [Small Snippet]

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM