簡體   English   中英

網絡接口參數

[英]Network Interfaces parameters

當我在windows命令提示符下輸入ipconfig /all時,我從網絡接口獲得了一堆參數信息。 有沒有辦法可以通過編程方式訪問它們? 例如,來自Java桌面應用程序?

例:

Wireless LAN adapter Wireless Network Connection:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Intel(R) Wireless WiFi Link 4965AGN
   Physical Address. . . . . . . . . : 00-1D-3B-5A-7A-88
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes

這是一個起點:

import java.util.*;
import java.net.*;

public class Test {
    public static void main(String[] args) throws Exception {
        Enumeration<NetworkInterface> interfaces =
            NetworkInterface.getNetworkInterfaces();
        while (interfaces.hasMoreElements())
        {
            NetworkInterface iface = interfaces.nextElement();
            System.out.println(iface.getDisplayName());
            for (InterfaceAddress address :
                 iface.getInterfaceAddresses())
            {
                System.out.println("  " + address);
            }
        }
    }
}

基本上,一旦有了NetworkInterface ,就應該能夠找到您想知道的其余大部分內容。 您可能希望過濾掉任何沒有地址的接口。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM