Java IP Address Get getLocalIP()

Here you can find the source of getLocalIP()

Description

get Local IP

License

Open Source License

Declaration

public static String getLocalIP() 

Method Source Code

//package com.java2s;
/* This file is part of Math4J.
 * Math4J is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.//  w w  w . j ava  2 s .  c o  m
 *
 * Math4J 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
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Math4J; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 * 
 * Copyright 2005 Anthony Magee
 */

import java.net.InetAddress;

import java.net.UnknownHostException;

public class Main {
    public static String getLocalIP() {
        String localIP = "0.0.0.0";
        try {
            localIP = InetAddress.getLocalHost().getHostAddress();
        } catch (UnknownHostException uhe) {
            System.out.println("IP for the local host could not be found.");
            uhe.printStackTrace();
        }

        return localIP;
    }
}

Related

  1. getLocalIp()
  2. getLocalIP()
  3. getLocalIp()
  4. getLocalIp()
  5. getLocalIP()
  6. getLocalIP()
  7. getLocalIP()
  8. getLocalIp()
  9. getLocalIp(final boolean useIpv6)