Tutorial 0 - Networking tools
One learning goal of this course is to introduce you to the basics of writing programs that make use of computer networking. Achieving this requires two or more programs to communicate via a network. This implies some sort of communication connection between the programs (i.e. processes) and the need to exchange data between the two. The rules for the exchange of this data are a protocol. Determining whether or not your program is compliant with a protocol can be challenging and it can be helpful to see exactly what your program is sending and how it responds to the data your program receives. The purpose of this tutorial is to introduce you to a collection of tools that you can use to explore the Internet.
Our first tool is netcat, a tool that you can use to explore how some text-based protocols operate. This command can be called either netcat
or nc
on your machine.
Anciently, there was another command called telnet that is somewhat similar, but it is insecure and should not used anymore. The Telnet protocol is specified in RFC 854 and tends to work the same on all machines. However, there is no standard implementation of netcat and there are some differences between the versions of netcat on Unix, Macs and Windows, where you may need to install it.
Note: There is no netcat on Windows 10.
You will be using netcat
so you will need a version of netcat that
works on your machine. If you are using Windows 10 there is the option for you
to use WSL (Windows Subsystem for Linux) on your machine. You will find
instructions for installing WSL online (MS Doc for
installing WSL). This takes some time. This is the best way to run netcat under Windows. It is possible to download and install open-source versions for netcat in windows itself, BUT these may not be secure and can trigger your anti-virus software.
On a mac, if you haven’t already, you likely will want to look into home-brew for Unix applications. There should already be an nc
(netcat) on your mac, but you can install a nicer version of netcat (also called nc) using home-brew. The home-brew one provides more flexibility and control.
Please make sure you have all the necessary software. If nothing works for you there is also the option of signing into one of the department machines and using netcat on that machine.
The transport protocol you will use for the first assignment is TCP. We will first use netcat to create and play with some TCP connections. TCP first creates a connection before it sends data. A TCP connection allows for two-way connection-oriented communication between two processes.
netcat dict.org 2628
Use the “help” command to discover what other commands the dictionary server responds to.
How many dictionaries does the server support?
What command would you use to discover the definition of the word “pemican”?
How many different dictionaries contain a definition of the word “protocol”?
What command would you use to find all the words that “sound like” the word “orange”?
The File Transfer Protocol (FTP) was one of the first widely used services on the Internet to transfer or download files from one machine to a client machine. There used to be many so called anonymous FTP servers but they are not as common any more because they can be a security risk. Today sFTP (secure FTP) is often used instead and the service is seldom left open. Nevertheless, there are still some open FTP servers out there (the UBC CS department hosts one of them).
Connect to host ftp.cs.ubc.ca, port 21, and type the following, noting the replies that the server gives you:
USER anonymous
PASS anonymous
PWD
PASV
at this point you will receive a sequence of 6 numbers (a,b,c,d,e,f). Without closing the connection, compute the next connection that you will be making. The host will be: a.b.c.d (based on the received numbers), and to the port will be the result of computing (e*256+f). For example, if you receive (128,10,32,41,10,8), use 128.10.32.41 as the host, and 10*256+8=2568 as the port.
Now open up a new shell and again use netcat to connect to the IP address and port you have calculated from the 6 numbers you received after the “PASV” command. Then return to the original terminal and type:
list
quit
If you see a list of files come out in the other terminal then you have managed to connect to the connection for data from the FTP server.
netcat example.com 80
GET / HTTP/1.0
Host: example.org
There are a number of other commands that can be used to explore the Internet. Figure out what each of the following commands do, and use the command to discover something about the Internet that you find interesting.
Open the Java tutorial on Sockets (https://docs.oracle.com/javase/tutorial/networking/sockets/). Read the entire tutorial, and then download and run the Knock Knock server and client code. Play around with the client, then modify the protocol code to add additional knock-knock jokes (just google knock knock jokes
). After doing it, modify the client to always send the correct response to the server, without getting user input (i.e., always send Who’s there
and whatever else is needed to keep the connection running). The client should repeat this process 10 times.