Homework 2

Due Monday 9/19 @ 11:59pm

Learning Objectives and Resources

The objective of this assignment is to become familiar with Networking teminology, the process of analyzing networks by calculating delays and throughput, and the available networking tools.

This assignment focuses on material from K&R Chapter 1.

You may also find the following resources useful:

  • Interactive Java Applets
  • Interactive Exercises

    Part 1: Questions from Ch. 1 (7th edition)

    Kurose & Ross, Ch 1. P16 (page 73)
    Kurose & Ross, Ch 1. P18 (page 73)
    Kurose & Ross, Ch 1. P25 (page 75)
    Kurose & Ross, Ch 1. P28 (page 75)

    Tools used in this homework assignment (for Part 2)

    For this assignment, you will need access to a UNIX command line. They are available on Linux and Mac OS X. If you use Windows, you will have to connect to csgateway.clarku.edu using PuTTY, and you may do so from your own computer.

    All the commands to be used in this assignment are denoted like command to run. It is understood that an ENTER key should be pressed when you finish typing a command. You will not be reminded again to hit the ENTER key.

    How to Connect to csgateway.clarku.edu

    nc (netcat)

    The nc program interfaces TCP or UDP sockets with the terminal, so you can craft requests and observe responses at the application protocol level (e.g. HTTP). It has many uses; we will explain a few specific uses later. View the man page (man nc) for useful help, or google "netcat".

    curl

    cURL is a command line tool to make HTTP requests to a web server without using a web browser. It is higher level than nc, in that it guarantees that you will be making a well-formed HTTP request.

    Part 2: Assignment

    All commands you used and the output produced for the following tasks should be saved in an document named username-hw02.doc, or if you want to use NotePad++ on Windows or Text Editor on Linux, save it as a text document named username-hw02.txt. Do the task in the UNIX command line prompt, and copy and paste the command you used and its output into the document. Each command will produce multiple lines of output. Answer all questions in the homework document as well.

    Required Task 1: Resolving Host

    When you enter a URL in the browser, it starts by looking up the hostname part of the URL and finding its IP address. This only needs to be done once every few hours, as the hostname-to-address mapping seldom changes. An IP address is a group of four numbers with periods between them, e.g. 123.45.67.89.

    Use the host command, find out the IP address of the following hosts or web sites.

    Required Task 2: Establishing Connection

    After the IP address of a host is determined, you can make connection to that computer if you know how to talk a common protocol. At the command prompt, once you enter the command nc -v -n ip-address port you will immediately begin talking to the host until the command prompt appears again. Perform the following tasks using nc and the IP addresses for the same hosts you figured out in the last part.

    Question

    1. Connect to csgateway.clarku.edu port 22 using the IP address you can figure out using the same technique as in Required Task 1. Port 22 is the port used by the SSH service. Upon connection, it will tell you the version of SSH csgateway is running. Just hit ENTER, and SSH should tell you "Protocol mismatch" and then you will see the bash prompt again. What is the version of the SSH service?

    2. Connect to csgateway.clarku.edu port 25. You can try a few commands on port 25 (eg. HELO yourname), but you probably won't get any response. What protocol is running on this port? (You can't do much useful here without authenticating)

    3. Connect to www.cs.clarku.edu port 80. This is the port used by the HTTP service. Once connected, it will not show any prompt this time. Repeat the connection as necessary for the following requests. For each request, explain the resulting HTTP response and what happens.

      1. Enter a correctly formatted HTTP GET request for the file /~jmagee/test.html.
      2. Enter a correctly formatted HTTP GET request for the file /~jmagee/test.txt.
      3. Enter a correctly formatted HTTP GET request for the file /~jmagee/nosuchfile.html.
      4. Enter a correctly formatted HTTP GET request for the file /~jmagee/privatefile.html.
      5. Enter a malformed request, such as "GO COUGARS GO!".

    4. In practice, you can give nc DNS name of the host instead if you remove the -n flag from the command. It will perform the DNS lookup for you. We may also omit the -v option, which will suppress the "Connection to ... succeeded!" message, nor will it show you "Connection refused" when there is a problem.

      Task 3: Making HTTP Requests

      We will now use curl to make HTTP requests for us. This simplifies a lot of typing. The command curl -i http://hostname/path will connect to hostname at port 80 and make the request for path on the host, using HTTP/1.1, a more recent version of HTTP than the HTTP/1.0 we used in last part.

      Visit the following URLs, first with a web browser, then with curl.

      Except for the file extension, the content of the two URLs are identical. The web browser renders hello.html as HTML, but hello.txt as text with visible HTML markup.

      Questions

    5. When using curl with the -i option, you also see the HTTP response headers before the content of the files are transmitted. Which of these headers might help the web browser decide how to present the URL, as HTML or as plain text?

    6. Look over the Facebook Graph API. Use curl to make a request for the Coca Cola page object with the URL https://graph.facebook.com/cocacola . How many "likes" does Coca Cola have? How could you write a program to find this automatically (very high level pseudocode, assume your program can use curl). Note: They seem to have updated the API since last time, requiring some authentication token. If you find a way around this please post on the facebook group. If you cannot do it with curl, use the Facebook API Explorer to see what you can access.

      What to Submit

      Submit your username-hw02.doc or username-hw02.pdf or username-hw02.txt file with the command outputs and the answers to these questions on Moodle by the due date and time.

      Grading Criteria

      Refer to the grading criteria file: hw02.criteria.

      Academic Honesty and Collaboration

      Cooperation is recommended in understanding programming concepts and system features. But the actual solution of the assignments including all programming must be your individual work. For example, copying without attribution any part of someone else's program is plagiarism, even if you have modified the code. The University takes acts of cheating and plagiarism very seriously.