利用NetworkInterface的getByName函式來選擇網路卡介面,接著便可以取得設定於此網卡上的所有IP。
try {
NetworkInterface iface = NetworkInterface.getByName("eth1");
Enumeration e = iface.getInetAddresses();
while(e.hasMoreElements()) {
InetAddress ip = (InetAddress)e.nextElement();
System.out.println(ip);
}
}
catch(Exception ex) {
ex.printStackTrace();
}
2007年7月25日 星期三
取得網卡的IP
訂閱:
張貼留言 (Atom)
0 意見:
張貼留言