Internet Addressing
description
Transcript of Internet Addressing
![Page 1: Internet Addressing](https://reader036.fdocuments.us/reader036/viewer/2022062519/56814f2a550346895dbcb660/html5/thumbnails/1.jpg)
Internet Addressing
![Page 2: Internet Addressing](https://reader036.fdocuments.us/reader036/viewer/2022062519/56814f2a550346895dbcb660/html5/thumbnails/2.jpg)
Introduction
The Internet is a vast collection of machines and devices spread out across the world.
There is an important need to identify and locate a specific one.
We will look into greater detail about how addresses work and how they are represented in Java.
![Page 3: Internet Addressing](https://reader036.fdocuments.us/reader036/viewer/2022062519/56814f2a550346895dbcb660/html5/thumbnails/3.jpg)
Local Area Network Addresses
Devices connected to a LAN have their own unique hardware address.
This address is useful only in the context of a LAN. In other words, it cannot be used to locate machines on the Internet.
This address cannot be used to indicate the location of a machine as it is possible to move the machine somewhere else (e.g. notebook computers).
![Page 4: Internet Addressing](https://reader036.fdocuments.us/reader036/viewer/2022062519/56814f2a550346895dbcb660/html5/thumbnails/4.jpg)
Java network programmers need not be concerned with details about how data is routed within a LAN. In fact, Java does not provide access to data link protocols (which are network dependent) used by LANs.
No matter what type of LAN is used, software can be written for it provided it supports TCP/IP (which is network independent).
![Page 5: Internet Addressing](https://reader036.fdocuments.us/reader036/viewer/2022062519/56814f2a550346895dbcb660/html5/thumbnails/5.jpg)
Internet Protocol Addresses
Devices having a direct Internet connection are allocated a unique IP address.
IP addresses may beStatic
Bound permanently to a certain machine/device
Dynamic Leased to a particular machine/device for a certain
period of time.
![Page 6: Internet Addressing](https://reader036.fdocuments.us/reader036/viewer/2022062519/56814f2a550346895dbcb660/html5/thumbnails/6.jpg)
The IP address is used by the Internet Protocol to route IP datagrams to the correct location.
![Page 7: Internet Addressing](https://reader036.fdocuments.us/reader036/viewer/2022062519/56814f2a550346895dbcb660/html5/thumbnails/7.jpg)
Structure of the IP Address
Under Internet Protocol version 4 (IPv4), the IP address is a 32-bit number made up of 4 octets. E.g: 192.168.1.1
There are 5 classes of IP addresses:Class A 0.0.0.0 to 127.255.255.255Class B 128.0.0.0 to 191.255.255.255Class C 192.0.0.0 to 223.255.255.255Class D 224.0.0.0 to 239.255.255.255Class E 240.0.0.0 to 247.255.255.255
![Page 8: Internet Addressing](https://reader036.fdocuments.us/reader036/viewer/2022062519/56814f2a550346895dbcb660/html5/thumbnails/8.jpg)
0 1 2 3 4 5 6 7 8 16 24 32
0
1 0
1 1 0
1 1 1 0
1 1 1 1 0
Network ID
Network ID
Network ID
Host ID
Host ID
Host ID
Multicast Group ID
Reserved for Future Use
A
B
C
D
E
![Page 9: Internet Addressing](https://reader036.fdocuments.us/reader036/viewer/2022062519/56814f2a550346895dbcb660/html5/thumbnails/9.jpg)
Each private network is allocated a network ID that is a unique identifier for a specific network. The network administrator is responsible for assigning host IDs to machines in the network.
The use of the classification scheme can help to reduce wastage of addresses.
![Page 10: Internet Addressing](https://reader036.fdocuments.us/reader036/viewer/2022062519/56814f2a550346895dbcb660/html5/thumbnails/10.jpg)
Obtaining an IP Address
The Internet Corporation for Assigned Names and Numbers (ICANN) is responsible for allocating blocks of IP addresses.
A person setting up a private network would be allocated either a Class A, B or C address, and could then assign host IP addresses to the machines on that particular network.
![Page 11: Internet Addressing](https://reader036.fdocuments.us/reader036/viewer/2022062519/56814f2a550346895dbcb660/html5/thumbnails/11.jpg)
Special IP Addresses
A loopback or localhost address (127.0.0.1) refers to the local machine.
It is useful for programmers to connect to the local machine for testing their network software. The connection using this address is possible whether or not there is a connection to the Internet.
![Page 12: Internet Addressing](https://reader036.fdocuments.us/reader036/viewer/2022062519/56814f2a550346895dbcb660/html5/thumbnails/12.jpg)
Another set of useful IP addresses are those reserved for private networking.
These addresses can be used safely within a private network as they are not exposed to the public Internet.Class A 10.0.0.0 to 10.255.255.255Class B 172.16.0.0 to 172.31.255.255Class C 192.168.0.0 to 192.168.255.255
On the Internet, routers will not forward data for these addresses.
![Page 13: Internet Addressing](https://reader036.fdocuments.us/reader036/viewer/2022062519/56814f2a550346895dbcb660/html5/thumbnails/13.jpg)
The Domain Name System
The domain name system (DNS) allows textual names to be associated with IP addresses.
Any entity, be it commercial, government or private, can apply for a domain name. The name can be used by people to locate that entity on the Internet.
![Page 14: Internet Addressing](https://reader036.fdocuments.us/reader036/viewer/2022062519/56814f2a550346895dbcb660/html5/thumbnails/14.jpg)
In addition, organizations can allocated their own hostnames once they have their domain name. Examples: ftp.davidreilly.com and www.davidreilly.com.
![Page 15: Internet Addressing](https://reader036.fdocuments.us/reader036/viewer/2022062519/56814f2a550346895dbcb660/html5/thumbnails/15.jpg)
How Does the DNS Work?
There are too many domain-name-to-IP-address mappings to handle on one system.
The DNS is a distributed database in which responsibility for accepting new registrations, and returning the addresses of existing registrations, is spread out across many different hosts.
![Page 16: Internet Addressing](https://reader036.fdocuments.us/reader036/viewer/2022062519/56814f2a550346895dbcb660/html5/thumbnails/16.jpg)
The distribution of such responsibilities forms an hierarchical structure such as shown below:
.net .com .gov .edu .mil .au .uk
davidreilly awl .co .org
![Page 17: Internet Addressing](https://reader036.fdocuments.us/reader036/viewer/2022062519/56814f2a550346895dbcb660/html5/thumbnails/17.jpg)
Domain Name Resolution When a request for a hostname is made (e.g:
www.aol.com), the operating system of the client computer contacts the local DNS server on the LAN.
The local DNS server needs to locate the domain server "aol.com". To do this, it queries the "root" level domain server, which refers it to the ".com".
When "aol.com" has been located, the local DNS server then queries it for the IP address of "www.aol.com"
![Page 18: Internet Addressing](https://reader036.fdocuments.us/reader036/viewer/2022062519/56814f2a550346895dbcb660/html5/thumbnails/18.jpg)
www.aol.com
get .com server
get aol server
ROOT DNS server
.com DNS server
LAN DNS server
![Page 19: Internet Addressing](https://reader036.fdocuments.us/reader036/viewer/2022062519/56814f2a550346895dbcb660/html5/thumbnails/19.jpg)
DNS requests can be cached on the LAN DNS server. This prevents overloading the root-level domains.
This also improves network performance as the delay between requesting a domain name and receiving a response is diminished.
![Page 20: Internet Addressing](https://reader036.fdocuments.us/reader036/viewer/2022062519/56814f2a550346895dbcb660/html5/thumbnails/20.jpg)
Internet Addressing with Java
In Java, IP addresses (whether in dotted decimal format or as a hostname) are represented as java.net.InetAddress objects.
Refer textbook (pg 63) for a description of some of the methods in the class InetAddress. http://java.sun.com/j2se/1.4.2/docs/api/java/net/InetAddress.html
![Page 21: Internet Addressing](https://reader036.fdocuments.us/reader036/viewer/2022062519/56814f2a550346895dbcb660/html5/thumbnails/21.jpg)
Example 1:A program to find out the IP address of the
current machine
Example 2:A program which resolves hostnames to IP
addresses and then attempts to perform a reverse lookup of the IP address.
DEMO`
DEMO
RUN
![Page 22: Internet Addressing](https://reader036.fdocuments.us/reader036/viewer/2022062519/56814f2a550346895dbcb660/html5/thumbnails/22.jpg)
import java.net.*;class LocalHostDemo {
public static void main(String args[]) {try {
InetAddress localAddr = InetAddress.getLocalHost();
System.out.print("IP address: ");System.out.println(localAddr.getHostAddress());System.out.println(localAddr.getHostName());
}catch (UnknownHostException uhe) {
System.out.println("Unable to resolve localhost");}
}}
![Page 23: Internet Addressing](https://reader036.fdocuments.us/reader036/viewer/2022062519/56814f2a550346895dbcb660/html5/thumbnails/23.jpg)
import java.net.*;class NetworkResolverDemo {
public static void main(String args[]) {if (args.length != 1)
System.out.println("Syntax: NetworkResolverDemo host");
try {InetAddress addr = InetAddress.getByName(args[0]);System.out.print("IP address: ");System.out.println(addr.getHostAddress());System.out.print("Hostname: ");System.out.println(addr.getHostName());
}catch (UnknownHostException uhe) {
System.out.println("Unable to resolve hostname");}
}}