Re: [問題] 如何抓取自己的ip
※ 引述《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)
推
10/01 21:52, , 1F
10/01 21:52, 1F
討論串 (同標題文章)
完整討論串 (本文為第 4 之 4 篇):
問題
1
1