Java IP Address Get getHostIP()

Here you can find the source of getHostIP()

Description

Method to return the IP address of the host computer

License

Open Source License

Return

The IP address of the host computer

Declaration

public static String getHostIP() 

Method Source Code

//package com.java2s;
/**/*from ww w.  ja  v  a2s.  c o  m*/
 * Archivists' Toolkit(TM) Copyright ? 2005-2008 Regents of the University of California, New York University, & Five Colleges, Inc.
 * All rights reserved.
 *
 * This software is free. You can redistribute it and / or modify it under the terms of the Educational Community License (ECL)
 * version 1.0 (http://www.opensource.org/licenses/ecl1.php)
 *
 * This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ECL license for more details about permissions and limitations.
 *
 *
 * Archivists' Toolkit(TM)
 * http://www.archiviststoolkit.org
 * info@archiviststoolkit.org
 *
 * Created by IntelliJ IDEA.
 * @author: Nathan Stevens
 * Date: Nov 26, 2008
 * Time: 11:08:31 AM
 */

import java.net.InetAddress;

public class Main {
    /**
     * Method to return the IP address of the host computer
     * @return The IP address of the host computer
     */
    public static String getHostIP() {
        try {
            InetAddress thisIp = InetAddress.getLocalHost();
            return thisIp.getHostAddress();
        } catch (Exception e) {
            e.printStackTrace();
            return "No IP Found";
        }
    }
}

Related

  1. getFirstNonLoopBackAddress(boolean preferIpv4, boolean preferIPv6)
  2. getHostIp()
  3. getHostIP()
  4. getHostIp()
  5. getHostIP()
  6. getHostIpAddress()
  7. getHostIPByHostName(String host)
  8. getInetIps()
  9. getIniFileInputStreamEclipse()