2011-12-08 67 views
1

当我在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 

回答

3

这里有一个出发点:

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你应该能够找到大部分你想知道什么,其余的。您可能希望过滤掉没有地址的任何接口。