推 boby730:用這種發法能成功嗎? 仍然不是對外IP +1 10/01 21:52
※ 引述《pao0111 (理想絕非空想)》之銘言:
: 或許可以試試看 NetworkInterface 這個類別:
: Enumeration<NetworkInterface> nis;
: nis = NetworkInterface.getNetworkInterfaces();
: while(nis.hasMoreElements())
: {
: NetworkInterface ni = nis.nextElement();
: System.out.println(ni);
: }
: 如果是 JRE 6.0 以上,還可以抓到像 MAC Address 這類的硬體位址。
使用InetAddress:
InetAddress[] allips;
try {
allips = InetAddress.getAllByName(InetAddress.getLocalHost().getHostName());
}catch(UnknownHostException uhe) {
uhe.printStackTrace();
}
for(InetAddress ip : allips) {
System.out.println(ip.getHostAddress());
}
※ 編輯: atthink 來自: 203.64.105.44 (09/28 11:08)