开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜