java-networking

Internet Addresses

IP (Internet Protocol) Address

An IP address is a unique address that identifies a device on the internet or a local network. IP addresses are typically in the format of a 32-bit number, represented as four decimal numbers separated by periods. Each decimal number represents 8 bits of the address.

Java supports two main types of IP addresses:

Domain Names

Resolved by DNS (Domain Name System) Servers

Domain names are human-readable names that correspond to the IP addresses of devices on the internet. Domain names are used in URLs to identify particular Web pages.

For example, in the URL http://www.example.com/index.html, the domain name is example.com.

The InetAddress Class

The InetAddress class in Java represents an Internet Protocol (IP) address. It encapsulates both the hostname and IP address of a network interface.

Creating new InetAddress objects

@throws UnknownHostException if the host name cannot be resolved

Static Methods

Example

    InetAddress address = InetAddress.getByName("www.tu.edu.np");

Getter Methods

Address Types

Global > Organisation-Local > Site-Local > Link-Local > Interface-Local

Testing Reachability

Object Methods

java.lang.Object

Inet4Address and Inet6Address

 public final class Inet4Address extends InetAddress

public final class Inet6Address extends InetAddress

Network Interface

The NetworkInterface Class

The NetworkInterface class in Java represents a network interface, providing methods to access the details of the physical or logical interface, such as its name, addresses, and other attributes. It is used to identify and work with the local network interface to which your system is connected.

Creating New NetworkInterface Objects

Similar to InetAddress, the NetworkInterface class does not have public constructors. You create instances of NetworkInterface using static factory methods.

@returns NetworkInterface object representing the network interface

@throws SocketException if encounters a problem while locating the relevant network interface

Static Factory Methods

Getter Methods