기본 콘텐츠로 건너뛰기

10월, 2019의 게시물 표시

gsjava 안드로이드 자신의 ip 얻기

String ip = "" ; String remote = mstr_remote ; try { for (Enumeration en = NetworkInterface. getNetworkInterfaces (); en.hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); if (!inetAddress.isLoopbackAddress()) { if (inetAddress instanceof Inet4Address) { ip = inetAddress.getHostAddress().toString(); Log. d ( TAG , "inetAddress host : " + ip); } } } } } catch (SocketException ex) { Log. e ( TAG , ex.toString()); }