Example usage for java.net InetAddress getHostAddress

List of usage examples for java.net InetAddress getHostAddress

Introduction

In this page you can find the example usage for java.net InetAddress getHostAddress.

Prototype

public String getHostAddress() 

Source Link

Document

Returns the IP address string in textual presentation.

Usage

From source file:net.librec.util.Systems.java

/**
 * Get IP of the System./* w w w  . j  a  v  a 2  s  . c  o  m*/
 *
 * @return IP of the System
 */
public static String getIP() {
    InetAddress ip = null;
    try {
        ip = InetAddress.getLocalHost();
    } catch (UnknownHostException e) {
        e.printStackTrace();
    }
    return ip.getHostName() + "@" + ip.getHostAddress();
}

From source file:com.ibm.watson.movieapp.dialog.fvt.config.SetupMethod.java

/**
 * serverUnderTest() - Check to see if automation is being run via Maven
 * @return - String containing baseURL to use for testing
 */// w ww  . j  a  v a2  s  . c  om
public static String serverUnderTest() {

    String ipAddress = "";
    String baseURL = "";

    String server = System.getProperty("app.url");

    if (server == null) {
        baseURL = Utils.readConfigProperty("serverUnderTest");
    } else {
        InetAddress localMachine = null;
        try {
            localMachine = InetAddress.getLocalHost();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        ipAddress = localMachine.getHostAddress();
        baseURL = server.replace("localhost", ipAddress);
    }

    return baseURL;
}

From source file:at.ac.tuwien.dsg.cloud.salsa.engine.utils.SystemFunctions.java

public static List<String> getEndPoints()
        throws MalformedObjectNameException, NullPointerException, UnknownHostException,
        AttributeNotFoundException, InstanceNotFoundException, MBeanException, ReflectionException {
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    Set<ObjectName> objs = mbs.queryNames(new ObjectName("*:type=Connector,*"),
            Query.match(Query.attr("protocol"), Query.value("HTTP/1.1")));
    String hostname = InetAddress.getLocalHost().getHostName();
    InetAddress[] addresses = InetAddress.getAllByName(hostname);
    ArrayList<String> endPoints = new ArrayList<>();
    for (Iterator<ObjectName> i = objs.iterator(); i.hasNext();) {
        ObjectName obj = i.next();
        String scheme = mbs.getAttribute(obj, "scheme").toString();
        String port = obj.getKeyProperty("port");
        for (InetAddress addr : addresses) {
            String host = addr.getHostAddress();
            String ep = scheme + "://" + host + ":" + port;
            endPoints.add(ep);/*from   ww w  .j  a v a  2s  . com*/
        }
    }
    return endPoints;
}

From source file:com.zz.cluster4spring.localinfo.DefaultLocalNetworkInfoProvider.java

public static void collectInterfaceIPs(NetworkInterface aNetworkInterface, List<String> aResult,
        InetAddressAcceptor aAcceptor) {
    for (Enumeration<InetAddress> addresses = aNetworkInterface.getInetAddresses(); addresses
            .hasMoreElements();) {/*from   ww  w .  j a  v  a2 s. co m*/
        InetAddress address = addresses.nextElement();
        if (aAcceptor.acceptInetAddress(aNetworkInterface, address)) {
            String hostAddress = address.getHostAddress();
            if (fLog.isInfoEnabled()) {
                fLog.info(MessageFormat.format("Found ACCEPTED IP:{0}", hostAddress));
            }
            aResult.add(hostAddress);
        } else if (fLog.isInfoEnabled()) {
            String hostAddress = address.getHostAddress();
            fLog.info(MessageFormat.format("Found SKIPPED IP:{0}", hostAddress));
        }
    }
}

From source file:com.cosmicpush.pub.push.EmailPush.java

public static EmailPush newPush(String toAddress, String fromAddress, String emailSubject, String htmlContent,
        String callbackUrl, String... traits) {

    InetAddress remoteAddress = PushUtils.getLocalHost();
    return new EmailPush(toAddress, fromAddress, emailSubject, htmlContent, callbackUrl,
            remoteAddress.getCanonicalHostName(), remoteAddress.getHostAddress(), BeanUtils.toMap(traits));
}

From source file:com.cosmicpush.pub.push.EmailPush.java

public static EmailPush newPush(String toAddress, String fromAddress, String emailSubject, String htmlContent,
        String callbackUrl, Map<String, String> traits) {

    InetAddress remoteAddress = PushUtils.getLocalHost();
    return new EmailPush(toAddress, fromAddress, emailSubject, htmlContent, callbackUrl,
            remoteAddress.getCanonicalHostName(), remoteAddress.getHostAddress(), traits);
}

From source file:Main.java

public static String getIpAddress() {
    try {/*from   www  .j a v a  2s. c  om*/
        for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en
                .hasMoreElements();) {
            NetworkInterface intf = en.nextElement();
            for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
                InetAddress inetAddress = enumIpAddr.nextElement();
                if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) {
                    // if (!inetAddress.isLoopbackAddress() && inetAddress
                    // instanceof Inet6Address) {
                    return inetAddress.getHostAddress().toString();
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static String getLocalIpBy3G() {
    try {/*  ww w.j  a  va2  s. co  m*/
        for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en
                .hasMoreElements();) {
            NetworkInterface intf = en.nextElement();
            for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
                InetAddress inetAddress = enumIpAddr.nextElement();
                if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) {
                    // if (!inetAddress.isLoopbackAddress() && inetAddress
                    // instanceof Inet6Address) {
                    return inetAddress.getHostAddress().toString();
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.paxml.selenium.rc.FileServer.java

public static String getHostIp() {
    try {/*from   w  ww . j a  v  a2s .  c o  m*/
        InetAddress addr = InetAddress.getLocalHost();
        return addr.getHostAddress();
    } catch (UnknownHostException e) {
        throw new PaxmlRuntimeException("Cannot get this machine's ip", e);
    }
}

From source file:com.beetle.framework.util.OtherUtil.java

/**
 * ?ip??char=2/*from ww  w.j a  v a 2s.c o  m*/
 * 
 * @return
 */
public static String getLocalHostIps() {
    StringBuffer sb = new StringBuffer();
    final char flag = 2;
    try {
        Enumeration<?> netInterfaces = NetworkInterface.getNetworkInterfaces();
        while (netInterfaces.hasMoreElements()) {
            NetworkInterface ni = (NetworkInterface) netInterfaces.nextElement();
            Enumeration<InetAddress> ips = ni.getInetAddresses();
            while (ips.hasMoreElements()) {
                InetAddress inetAddress = ips.nextElement();
                String ip = inetAddress.getHostAddress();
                if (!inetAddress.isLoopbackAddress() && ip.indexOf(":") == -1) {
                    sb.append(ip).append(flag);
                }
            }
        }
    } catch (Exception e) {
        return "";
    }
    return sb.toString();
}