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(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()
精彩评论