달력

4

« 2024/4 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
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
반응형
:
Posted by mapagilove