Advanced Java (2160707)

BE | Semester-4   Winter-2018 | 20-11-2018

Q2) (a)

Write a java program to find an IP address of the machine on which the program runs?

Program

import java.net.InetAddress;
public class IP_Address
{
    public static void main(String args[]) throws Exception
    {
        InetAddress IP = InetAddress.getLocalHost();
        System.out.println("IP of my system is := "+IP.getHostAddress());
    }
}

Output

IP of my system is := 127.0.1.1