JAVA Program to check IP Address.


IP Address:

IP stands for Internet Protocol.

IP address is expressed as four decimal numbers ranging from 0 to 225, separated by periods, with each of four numbers representing (8) bits of the address for a total length of thirty-two (32) bits of the whole address. This format is called dotted quad notation.

Every machine on the Internet has a unique number assigned to it, called an IP Address. Without a unique IP address on your machine, you will jot be able to communicate with other devices, users on over Internet.

ADVERTISEMENT



        An IP address is a numerical number label assigned to each device (e.g. computer, printer, scanner etc) participating in a computer network that uses the Internet Protocol for communication. It designates the specific location of a device on the network. Every device on Internet has its unique IP address which means no two devices on Internet can have same IP address.

        An IP address consists of 32 bits of information. These bits are divided into four sections referred to as octets or bytes, each containing 1 byte(8 bits).


JAVA program to check IP Address:

import java.io.IOException;
import java.net.InetAddress;
//InetAddress This class represents an Internet Protocol (IP) address.

//An IP address is either a 32-bit or 128-bit unsigned number used by IP,

// a lower-level protocol on which protocols like UDP and TCP are built.
public class CheckingIPAddress
{
public static void main(String[] args) throws IOException {

InetAddress IP_address = InetAddress.getLocalHost();

//getLocalHost() Returns the address of the local host.

System.out.println("IP Address of my device is: "+IP_address.getHostAddress());

//getHostAddress() Returns the IP address string in textual presentation.
//returns the raw IP address in a string format.
}

}
This program will display the IP address of your system when you run it.
Previous Post Next Post

Contact Form