20-755: The Internet Homework 1: Introduction to Internet programming Assigned: Friday, July 16. Due: 10:30am, Monday, July 26. Team members: (1) (2) (3) ************ Introduction ************ The aim of this homework is to teach you some basics of Internet programming that will help you get started on your project. When you're finished you'll understand some of the capabilities of DNS and you'll have written a simple but nonetheless real server that you can use as a template for your project. Please make sure that you understand the solutions for all of the tasks, even if another group member developed the solution. In particular you should be able to explain each line of code in your group's echo server and know how to perform DNS zone transfers, as these concepts will likely show up on the final. The homework, which is 20% of your final grade, consists of 5 tasks totaling 100 points and a 20-point extra credit question. Each group member will receive the same score. All tasks should be performed on euro.ecom. Julio will be holding recitations on Monday and Friday to help you with the homework tasks. And please don't hesitate to ask either one of us for help if your group gets stuck. ******************************* Task 1. Getting started (10 pts) ******************************* Use Emacs to create a Perl5 program called "printit.pl" that reads each line of an input ASCII text file from stdin, prepends ":" to each line, and prints the result to stdout. For example, if the file foo consists of the following two lines: abc def then running "printit.pl < foo" on euro.ecom should generate the following output: euro.ecom.cmu.edu:abc euro.ecom.cmu.edu:def Use the "hostname()" function in the standard Sys::Hostname module to get your own host name. E.g.: #!/usr/local/bin/perl5 -w use Sys::Hostname; $host = hostname() || die "couldn't get hostname: $!"; (The -w option instructs the Perl interpreter to print out useful warning message. Every Perl script you write should include this option.) Run your printit.pl program on euro.ecom and redirect the output to a file. Paste both the source Perl5 program and its output on euro.ecom below: ANSWER: Paste the source file here: Paste the output file here: ***************************************************************** Task 2. Translating between IP addresses and domain names (10 pts) **************************************************************** (2a) What is the IP address for kittyhawk.cmcl.cs.cmu.edu? ANSWER: (2b) What is the domain name for 128.2.185.143? ANSWER: This task can be performed with nslookup in non-interactive mode. Refer to the nslookup man page for details by typing "man nslookup" to the shell. ***************************************** Task 3. Finding DNS name servers (10 pts) ***************************************** (3a) What are the four name servers for the cs.cmu.edu domain? ANSWER: For this task you will need to use nslookup in interactive mode. Use the "set type=ns" command to tell nslookup that you want information on name servers. ************************************************* Task 4. Surveying the CMU CS Internet (30 points) ************************************************* (4a) How many hosts are in the cs.cmu.edu domain? ANSWER: In nslookup interactive mode, use the "server " command to tell nslookup to query one of the cs.cmu.edu nameservers that you identified in Task 3. Then perform a zone transfer using the "ls" command with the output redirected to a file. Use wc to count the number of lines in the resulting file. Warning: For no good reason, when you redirect the output of the nslookup "ls" command, there must be a space after the ">" character that redirects the result of your query to a file. That is, you must type "ls ... > filename" and not "ls ... >file". (4b) How many of the domain name from (4a) are INTEL machines? ANSWER: For this part you can "grep" the output file from the zone transfer for the string INTEL and then pipe the results into "wc". See the man pages for grep and wc for more info. (4c) How many of the INTEL machines from (4b) are running LINUX or UNIX? ANSWER: For this part, pipe the output of one grep into another, and then pipe the output of this grep to "wc", once for LINUX and once for UNIX. *************************************** Task 5. Writing an echo server (40 pts) *************************************** The simplest Internet server of all is the echo server. An echo server waits for a connection request from a client to arrive at some port, and then echos each input line it receives over that connection back to the client. Not every Internet host has an echo server, but those that exist listen on port 7. You can try one out for yourself using telnet as the client: % telnet n2.sp.cs.cmu.edu 7 When you are finished, type "^]" followed by the RETURN (ENTER) key to get the telnet prompt. Then type "quit" to get back to the shell. Your task is to write an echo server on euro.ecom called "echo.pl" that listens on some port between 11000 and 22000 for TCP connection requests from clients, creates a connection when a request arrives, and then echos each input line that arrives on that connection back to the client. Your server should use the "IO::Socket" module: #!/usr/local/bin/perl5 -w use IO::Socket; You can use the "perldoc" command to read about this module. Parts might be cryptic, so we'll also be covering it in class and recitation: % perldoc IO::Socket > socketdoc.txt You can test your server using telnet as a client: % telnet euro.ecom Notice that the telnet client and the echo server can both be running on euro.ecom at the same time, which might simplify debugging. Also, you'll find it very helpful to sprinkle your code with print statements while you are debugging so you can track the status of your server. E.g, print "awaiting next connection request\n" print "received connection request\n"; print "received $line from client\n"; print "sent $line to client\n"; print "client closed connection\n"; Mail me the port number your group is using and I'll post them off the H1 link so we'll be sure to avoid port collisions. ANSWER: Paste the source code for your echo server here: ********************* Extra credit (20 pts) ********************* How many of the domain names in the cs.cmu.edu domain correspond to machines that are actually up and running? ANSWER: What do your results imply about Internet domain surveys that rely only on DNS zone transfers? ANSWER: ***************** Handin directions ***************** Fill in a copy of this ASCII text file (don't forget to fill in your team members at the top!) and mail it to droh@cs as a text file (not a Word document, please) by the due date. If none of this makes any sense yet, don't panic. We'll be covering DNS and server design in lecture and recitation Monday. Things will be much clearer then. Good luck!