You are on page 1of 14

Internet Address

Zamzam Abdullah Al-Suti


Host

 Any device that enable to connect to the internet.

 It includes routers, printers, fax machines, soda machines, bat houses, etc.

 Every host which is connected to a network can be identified by a unique, four-byte


Internet Protocol (IP) address.
Doman name system(dns)

 Numeric addresses are mapped to names like www.blackstar.com or star.blackstar.com by


DNS.

 Each site runs domain name server software that translates names to IP addresses and vice
versa

 DNS is a distributed system


The InetAddress Class

 The java.net.InetAddress class represents an IP address.

 It converts numeric addresses to host names and host names to numeric addresses.

 It is used by other network classes like Socket and ServerSocket to identify hosts
How to create InetAddresses

 There are no public InetAddress() constructors.

 No object can created by calling constructor.

 The methods of creating InetAddress object:

 getByName()

 getByAllName()

 getLocalHost()
The getByName() factory method

public static InetAddress getByName(String host) throws


UnknownHostException

InetAddress utopia, duke;


try {
utopia = InetAddress.getByName("utopia.poly.edu");
duke = InetAddress.getByName("128.238.2.92");
}
catch (UnknownHostException e) {
System.err.println(e);
}
Other ways to create InetAddress objects

public static InetAddress[] getAllByName(String host) throws


UnknownHostException

public static InetAddress getLocalHost() throws


UnknownHostException
Getter Methods:

 public boolean isMulticastAddress()


 public String getHostName()
 public byte[] getAddress()
 public String getHostAddress()
Utility Methods:

 public int hashCode()


 public boolean equals(Object o)
 public String toString()
simple example of InetAddress class to get ip
address of www.javatpoint.com website.
import java.io.*;  

import java.net.*;  

public class InetDemo{  

public static void main(String[] args){  

try{  

InetAddress ip=InetAddress.getByName("www.javatpoint.com");  

  

System.out.println("Host Name: "+ip.getHostName());  

System.out.println("IP Address: "+ip.getHostAddress());  

}catch(Exception e){System.out.println(e);}  

}  

}  

a
Ports

 has only one Internet address

 This address is subdivided into 65,536 ports

 Ports are logical abstractions that allow one host to communicate simultaneously with
many other hosts

 Many services run on well-known ports. For example, http tends to run on port 80.
Protocols

 defines how two hosts talk to each other.

 The daytime protocol, RFC 867, specifies an ASCII representation for the time that's

legible (readable) to humans.

 The time protocol, RFC 868, specifies a binary representation, for the time that's legible to

computers.
IETF RFCs

 Requests For Comment

 Document how much of the Internet works

 Various status levels from obsolete to required to informational

 TCP/IP, telnet, SMTP, MIME, HTTP, and more

 http://www.faqs.org/rfc/
References:

 https://www.javatpoint.com/InetAddress-class.

 https://www.javatpoint.com/InetAddress-class

 https://www.codejava.net/java-se/networking/java-inetaddress-examples

You might also like