Java Utililty Methods Local Address Get

List of utility methods to do Local Address Get

Description

The list of methods to do Local Address Get are organized into topic(s).

Method

StringgetLocalAddress()
get Local Address
try {
    return InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
    try {
        return InetAddress.getLocalHost().getHostName();
    } catch (UnknownHostException e1) {
        return "localhost";
StringgetLocalAddress()
get Local Address
try {
    Enumeration<NetworkInterface> enumeration = NetworkInterface.getNetworkInterfaces();
    ArrayList<String> ipv4Result = new ArrayList<String>();
    ArrayList<String> ipv6Result = new ArrayList<String>();
    while (enumeration.hasMoreElements()) {
        final NetworkInterface networkInterface = enumeration.nextElement();
        final Enumeration<InetAddress> en = networkInterface.getInetAddresses();
        while (en.hasMoreElements()) {
...
StringgetLocalAddress()
get Local Address
String addr = null;
try {
    InetAddress ia = InetAddress.getLocalHost();
    if (ia != null)
        addr = ia.getHostAddress();
} catch (UnknownHostException uhe) {
return addr;
...
StringgetLocalAddress(final String start, final String end)
get Local Address
return start + "localhost:" + getNextAvailablePort() + end;
InetSocketAddressgetLocalAddress(int port)
get Local Address
String hostInfo = null;
try {
    hostInfo = InetAddress.getLocalHost().getHostName();
    InetAddress.getByName(hostInfo);
    return new InetSocketAddress(hostInfo, port);
} catch (UnknownHostException e) {
return new InetSocketAddress(InetAddress.getLocalHost().getHostAddress(), port);
...
InetSocketAddressgetLocalAddress(int port)
get Local Address
String ipAddress = InetAddress.getLocalHost().getHostAddress();
return new InetSocketAddress(ipAddress, port);
URLgetLocalAddress(int port)
get Local Address
try {
    return new URI("http://localhost:" + port).toURL();
} catch (URISyntaxException | MalformedURLException e) {
    throw new RuntimeException(e);
InetAddressgetLocalAddress(String adaptorName)
get Local Address
try {
    Enumeration<NetworkInterface> b = NetworkInterface.getNetworkInterfaces();
    while (b.hasMoreElements()) {
        NetworkInterface networkInterface = b.nextElement();
        if (networkInterface.getName().equals(adaptorName)) {
            for (InterfaceAddress f : networkInterface.getInterfaceAddresses()) {
                if (f.getAddress().isSiteLocalAddress()) {
                    return f.getAddress();
...
StringgetLocalAddress(String filter)
get Local Address
if (filter == null) {
    InetAddress addr;
    try {
        addr = InetAddress.getLocalHost();
        return addr.getHostAddress().toString();
    } catch (UnknownHostException e) {
        throw new RuntimeException("Failed to getLocalAddress", e);
Pattern filterPattern = Pattern.compile(filter);
try {
    Enumeration<NetworkInterface> networks = NetworkInterface.getNetworkInterfaces();
    while (networks.hasMoreElements()) {
        NetworkInterface network = networks.nextElement();
        Enumeration<InetAddress> addresses = network.getInetAddresses();
        while (addresses.hasMoreElements()) {
            String address = addresses.nextElement().getHostAddress();
            Matcher m = filterPattern.matcher(address);
            if (m.matches()) {
                return address;
} catch (SocketException e) {
    throw new RuntimeException("Failed to getLocalAddress", e);
throw new RuntimeException("Failed to getLocalAddress");
InetAddressgetLocalAddress0()
get Local Address
InetAddress localAddress = null;
try {
    localAddress = InetAddress.getLocalHost();
    if (isValidAddress(localAddress)) {
        return localAddress;
} catch (Exception e) {
    e.printStackTrace();
...