Task 1. #!/usr/local/bin/perl5 -w use Sys::Hostname; $host = hostname() || die "couldn't get hostname: $!"; $line = ; while ($line) { print "$host:", $line; $line = ; } Task 2 2a. 128.2.194.242 Solution: % nslookup kittyhawk 2a. kittyhawk.cmcl.cs.cmu.edu Solution: % nslookup 128.2.194.242 Task 3. PEACH.SRV.cs.cmu.edu internet address = 128.2.242.81 BANANA.SRV.cs.cmu.edu internet address = 128.2.242.182 MANGO.SRV.cs.cmu.edu internet address = 128.2.222.180 BLUEBERRY.SRV.cs.cmu.edu internet address = 128.2.203.61 % nslookup > set type=ns > cs.cmu.edu Task 4. (4a) There are 5673 hosts in cs.cmu.edu. % nslookup % server mango % ls cs.cmu.edu > hosts Then edit out the few non-host names (e.g., OBJECT) that identify subdomains with their own DNS servers. % wc -l hosts 5673 (4b) 1,822 Intel boxes (grep -i intel hosts |wc -l) (4c) 209 + 176 = 385 Unix boxes (grep -i intel hosts | grep -i linux wc -l) (grep -i intel hosts | grep -i unix wc -l) Problem 5. #!/usr/local/bin/perl5 -w use IO::Socket; # # echo server # $port = 8000; # create a TCP listen socket on port $port $server = IO::Socket::INET->new(LocalPort => $port, Type => SOCK_STREAM, Reuse => 1, Listen => 10) or die "Couldn't listen on port $port: $@\n"; # loop forever waiting for requests while(1) { # wait for a client's connection request $client = $server->accept(); # echo the input back to the client until end of file $line = <$client>; while ($line) { $client->print($line); $line = <$client>; } # close the server side of the connection close $client; } Extra credit: #!/usr/local/bin/perl5 -w use Net::Ping; # always flush stdout select((select(STDOUT), $| = 1)[0]); # # read in list of hostname/IP address pairs # $up = $down = 0; $timeout = 1; while (defined($line = )) { chomp($line); ($host) = split(" ",$line); if (pingecho($host,$timeout)) { print ("u"); $up++; } else { print ("d"); $down++; } } # summarize the results print "\n\n$up up + $down down = ",$up+$down, " total\n"; # end of ping program Results: 839 up 4834 down 5673 total