get Ip Address from Inet4Address - Java Network

Java examples for Network:IP Address

Description

get Ip Address from Inet4Address

Demo Code


//package com.java2s;
import java.net.Inet4Address;
import java.net.UnknownHostException;

public class Main {
    public static void main(String[] argv) throws Exception {
        System.out.println(getIpAddress());
    }//from  ww w.  j  a v  a 2s.com

    public static String getIpAddress() throws UnknownHostException {
        return Inet4Address.getLocalHost().getHostAddress();
    }
}

Related Tutorials