Java Local Address Get getLocalAddress()

Here you can find the source of getLocalAddress()

Description

get Local Address

License

Apache License

Declaration

static String getLocalAddress() 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.net.InetAddress;

import java.net.UnknownHostException;

public class Main {
    static String getLocalAddress() {
        try {/*from   w  ww.ja  va  2 s.c  o m*/
            return InetAddress.getLocalHost().getHostAddress();
        } catch (UnknownHostException e) {
            try {
                return InetAddress.getLocalHost().getHostName();
            } catch (UnknownHostException e1) {
                return "localhost";
            }
        }
    }
}

Related

  1. getLocalAddress()
  2. getLocalAddress()
  3. getLocalAddress()
  4. getLocalAddress()
  5. getLocalAddress()
  6. getLocalAddress()
  7. getLocalAddress()
  8. getLocalAddress(final String start, final String end)
  9. getLocalAddress(int port)