안드로이드 이야기
안드로이드 - 자기 IP주소 가져오기
mapagilove
2013. 3. 28. 10:17
728x90
반응형
안드로이드 - 자기 IP주소 가져오기
원본 출처 :http://eduinfo.pe.kr/bbs/board.php?bo_table=01_6&wr_id=2549
public String getLocalIpAddress() {
try {
Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
while(en.hasMoreElements()) {
NetworkInterface interf = en.nextElement();
Enumeration<InetAddress> ips = interf.getInetAddresses();
while (ips.hasMoreElements()) {
InetAddress inetAddress = ips.nextElement();
if (!inetAddress.isLoopbackAddress()) {
return inetAddress.getHostAddress().toString();
}
}
}
} catch (SocketException ex) {
Log.e("Error", ex.toString());
}
return null;
}
728x90
반응형