02152  Concurrent Systems - NP Lab 1: Internet Notions
Technical University of Denmark DTU
02152 Concurrent Systems        Fall 2008
NP Lab 1: Internet Notions
Home Plan Material  

Purpose

These exercises are all experiments which are intended to give you a better understanding of networks and network programming.

Time and Place

Assistance for this programming lab will be available in the G-databar, Building 308, Rooms 15 + 16, Thursday, October 23, 15-17.

[The exercises should run readily on all Unix-based systems, although some variations in command syntax and output may occur. On Windows-based systems, you are on your own and will need to investigate for yourself how some of the pieces of information asked for here can be found.]

Preparations

This describes the first set of practical exercises for the Network Programming part of the course in Concurrent Systems. The exercises assume that you have read at least Sections 1 to 6 of ``The Poor Man's Guide to Computer Networks and their Applications'' [PMG].

1 Naming and Adressing

The Java class java.net.InetAddress contains a number of methods for dealing with Internet host names and the corresponding IP addresses. Write a Java program which enables the user to type in one or more host names and which for each name prints out the name and the corresponding IP address. The easiest way to do this is for each host name to create an InetAddress object with the given host name, and then to use the methods associated with this object in order to find the corresponding IP address. Note that instances of the object cannot be created by new, but are obtained by calling the static method InetAddress.getByName(). The program should deal sensibly with the situation where there is no IP address corresponding to a given name.

You may use the program LineCopy.java as your starting point.

Test your program out on the following host names:

    www.imm.dtu.dk
    www.rfc-editor.org
    www.spoof.net
    www.spoog.net
    ftp.opasia.dk
    fup.orm.it

Try also to see what happens if you supply an empty string as the host name.

The Unix command host can be used to find the IP address corresponding to a given Internet host name. Use the command to check the results produced by your program. [On some systems, only the older nslookup command is available.]

2 Routing

The Unix command traceroute can be used to find the route via which IP will transfer data to a given destination. Try this out using each of the following host names as parameters to the command:

    www.imm.dtu.dk
    www.rfc-editor.org
    www.imag.fr
    www.microsoft.com
    www.unsw.adfa.edu.au
    ftp.opasia.dk

By looking at each destination a number of times (preferably over a period of time of the order of days), try to determine to what extent the route selected for a given destination changes with time.

Note: On some systems, use of commands like traceroute has been disabled. Likewise, a node may refuse to respond to the IP probes sent out by traceroute or the probe (or its response) may simply be caught by a firewall. In such cases, a timeout will occur indicated by (*). See the man pages for more information.

3 Ports

You should by now be aware that TCP ports are associated with the endpoints of TCP connections, and that ports with particular numbers identify the endpoints associated with servers who can provide particular Internet services, such as SMTP (port 25), HTTP (port 80) and so on. But what happens at the client's end of the connection?

Perform some experiments to discover what port the client is attached to when a connection is made to some servers offering standard Internet services. Do this by writing a little Java program which can run as a trivial client for various servers. Your program should be able repeatedly to:

For more details of how to create a client socket and how to get information about the socket which you have created, consult the documentation for the Java class java.net.Socket. You may be able to get inspiration for how to set up and close the connection by looking at the skeleton client in [PMG 9.1]. Note, however, that in this exercise you do not need to transfer any data between the client and the server (or vice versa).

WARNING: If you make stupid mistakes in your program, you may cause a Denial-of-Service situation to occur. (Why?) In particular, it is very important to remember to close the connections which you set up when you have finished using them. In order not to disturb computer systems outside DTU, I also strongly suggest that you only try to make connections to local DTU servers, such as:

Host Port Service
www2.imm.dtu.dk 80 HTTP
mail.imm.dtu.dk 25 SMTP
galadriel.imm.dtu.dk 80 HTTP

4 Network Information from the OS

The Unix command netstat enables you to investigate the state of the local network interfaces, routing tables and connections. Try for example the commands:

    netstat -i
    netstat -r
    netstat -f inet

If you cannot understand the responses from these commands, look at the relevant manual page, by using the command man netstat.

The Unix command ifconfig enables you to investigate in more detail the network interfaces in your computer. The command is often used to set interface parameters, but to do this you need special privileges. However, no special privileges are needed in order to read the status of the interfaces, which you can do by just executing the command without any parameters. On most Unix systems this is done by typing:

   /sbin/ifconfig -a

(Note that it is ususally necessary to give the full path /sbin/... because this command is not usually on the search path for ordinary users.)

Finally, you can learn a lot about now things are screwed together in the network by looking in some of the files consulted by the operating system. In particular, use the more command to type out the contents of:

    /etc/resolv.conf
    /etc/services

The /etc/resolv.conf files contains information used for resolving names. Typically, it contains at least two pieces of information:

  1. A default network domain name to be used if an incomplete host name is supplied (field domain). For example, if the default domain name is x.y.z, and a host name h23 is supplied, then the full host name is resolved to be h23.x.y.z.
  2. The IP addresses of one or more DNS servers to be consulted first in order to find IP addresses corresponding to given Internet host names (field nameserver). There may be several of these.

The /etc/services file contains a list of Internet services and the port numbers to be used if the relevant server is set up on the computer on which you are looking at the file. The content of this file is more or less self-explanatory.

[Originally by Robin Sharp, 2002-2003. Modified by Hans Henrik Løvengreen 2004-2008.]
Hans Henrik Løvengreen, Oct 22, 2008