A little networking
Upload via Moodle as: networking.pdf or .md or .txt
Goals
- Learn some basic networking vocabulary
- Use
ncas a client and a server - Use python's built-in HTTP server
- Use
curlas an HTTP client
Rubric
The questions
Keep your answers short, write them up, and submit them as described at the top of this page. Really truly, short and simple is sufficient!
Vocabulary. For each of the following terms, give a short definition.
- client
- server
- protocol
- TCP connection
- port
- well-known port
Common clients, servers, and protocols.
- List three clients that you use regularly (for different services).
- For each of those clients, name one protocol it supports.
- Name one server (the software, not the domain name) that supports the HTTP and HTTPS protocols. (Such servers are typically called "web servers".)
Set up nc on your computer. The netcat command is a flexible tool for exploring networks. The actual command name is going to depend on your installation (
nc,netcat, orncat), but it's most commonly callednc.If you're on macOS or Linux:
ncis already installed. Trywhich ncto make sure.If you're on Windows with WSL installed:
ncshould already be installed.If you're on Windows without WSL: Download and install the nmap package, which includes several great networking applications.
Simple client/server example. The daytime protocol is about as simple as internet protocols get. (1) The client establishes a TCP connection with the daytime server; (2) the server sends a string representing the current date and time back to the client; and (3) the server closes the connection.
Try it, like so.
- Pick an IP address from this list of daytime servers.
- Execute the command
nc IP_OF_DAYTIME_SERVER DAYTIME_PORT(where you need to fill in the two command-line arguments in question).
Answer these questions.
- What is the well-known port for the daytime protocol?
- In the exercise described above, what software acts as the client?
Using nc as both client and server.
- NOTE: you will need to be on the Carleton network for this exercise.
- Figure out your computer's IP address, which I will call YOUR_IP.
- Open one terminal, logged into mantis.
- Open another terminal on your own computer.
- Pick a random-ish port number between 8000 and 65000. I'll refer to this port as YOUR_PORT.
- In your local terminal, set up your server.
- Windows and Linux:
nc -l -p YOUR_PORT - macOS:
nc -l YOUR_PORT
- Windows and Linux:
- In the mantis terminal,
execute
nc YOUR_IP YOUR_PORT. - Type something in each terminal and hit Enter.
- When you're done playing around, hit Ctrl-C in both terminals.
Questions:
- How did you figure out your computer's IP address?
- What does the
-lstand for in the firstnccommand? - Which of the two
nccommands is acting as the server, and which is acting as the client, and how can you tell? - If you switch the roles of the mantis and local terminals, does the connection work? Any guesses why not?
nc with two local terminals
Try the previous exercise using two local terminal windows. Instead of YOUR_IP, use the symbol
localhost.- Did it work? (Should be yes.)
- To what IP address does
localhostcorrespond?
nc with a friend
Try the previous exercise using a friend's computer (both of you on the Carleton network) instead of mantis.
- Did it work? (Should be yes.)
- If you switched roles, did it still work? (Also should be yes.)
- Why was this different from using mantis?
Talking to a web server, part 1
- Execute
curl https://jeffondich.com/. What do you see? (a summary is sufficient) - Execute
curl -v https://jeffondich.com/. You get some more stuff in addition to what you saw before. Summarize the new stuff. - In the previous question, you saw a "200" in the output. What is the role of that 200?
- Execute
curl -v http://jeffondich.com/. What do you get now, and why? - Execute
curl -v https://jeffondich.com/blahblahblah. What do you get now, and why?
- Execute
Talking to a web server, part 2
- Execute
nc cs208.jeffondich.com 80. What do you see? - Now (assuming the previous command is still running), type the following:
GET / HTTP/1.1 Host: cs208.jeffondich.com
NOTE: you need that blank line after the "Host" line.
What do you see now?
- What do you see if you do the same thing, but this time you do
/moose.htmlinstead of just/in theGETline? - What does a browser do differently from curl to make sure you see a picture of a moose? (Though "curl is text-only" is one answer, I'm looking for a different answer, about a step that Firefox or Chrome or Safari would take that curl does not when visiting this web page.)
- Execute
That's enough for now...
...but I encourage you to keep playing with this kind of thing. It's fun, and you can learn a lot!