Presentation is loading. Please wait.

Presentation is loading. Please wait.

Internet Addressing. Introduction The Internet is a vast collection of machines and devices spread out across the world. There is an important need to.

Similar presentations


Presentation on theme: "Internet Addressing. Introduction The Internet is a vast collection of machines and devices spread out across the world. There is an important need to."— Presentation transcript:

1 Internet Addressing

2 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.

3 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).

4 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).

5 Internet Protocol Addresses Devices having a direct Internet connection are allocated a unique IP address. IP addresses may be  Static Bound permanently to a certain machine/device  Dynamic Leased to a particular machine/device for a certain period of time.

6 The IP address is used by the Internet Protocol to route IP datagrams to the correct location.

7 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 A0.0.0.0 to 127.255.255.255  Class B128.0.0.0 to 191.255.255.255  Class C192.0.0.0 to 223.255.255.255  Class D224.0.0.0 to 239.255.255.255  Class E240.0.0.0 to 247.255.255.255

8 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 Host ID Multicast Group ID Reserved for Future Use A B C D E

9 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.

10 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.

11 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.

12 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 A10.0.0.0 to 10.255.255.255  Class B172.16.0.0 to 172.31.255.255  Class C192.168.0.0 to 192.168.255.255 On the Internet, routers will not forward data for these addresses.

13 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.

14 In addition, organizations can allocated their own hostnames once they have their domain name. Examples: ftp.davidreilly.com and www.davidreilly.com. ftp.davidreilly.com www.davidreilly.com

15 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.

16 The distribution of such responsibilities forms an hierarchical structure such as shown below:.net.com.gov.edu.mil.au.uk davidreilly awl.co.org

17 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"

18 www.aol.com get.com server get aol server ROOT DNS server.com DNS server LAN DNS server

19 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.

20 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/I netAddress.html http://java.sun.com/j2se/1.4.2/docs/api/java/net/I netAddress.html

21 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

22 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"); }

23 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"); }


Download ppt "Internet Addressing. Introduction The Internet is a vast collection of machines and devices spread out across the world. There is an important need to."

Similar presentations


Ads by Google