Showing posts with label IP Address. Show all posts
Showing posts with label IP Address. Show all posts

Thursday, 14 August 2014

Write a Program in Java which get the Host IP address

Structure of the Problem Requirements 

In this problem we will learn how to take IP address in Java Program . IP address exist in Java InetAddress class , create an instance of this class and then get the IP address with  method getHostAddress . This method is mostly used when we deal with networking in Java. Here is the Source Code of this problem which help you in better understanding .

Source Code

package com.lepnetworking.com;

import java.net.InetAddress;
import java.net.UnknownHostException;


public class Net_working {

    public static void main(String[] args) throws UnknownHostException {
        InetAddress ip = InetAddress.getLocalHost();
    System.out.println( " Your IP Address is : " + ip.getHostAddress());
    }
    
}

Output of the Program

Java Networking Programming
Host Ip address