Your Goal: Make a port scanner.
The Client: It should do the following
For every port on euclid.nmu.edu from 1 ... 99 inclusive, you should try and open that port. Tell the user if it opens or fails to open. If it does open, close it.
Sample output
No: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
Grading
Points |
Task |
1 |
Every variable has a comment describing it's use |
-2 |
Code indented wrong |
1 |
Turned in before Monday Jan 21 4:00pm |
-1 |
Turned in after Wednesday Jan 23 at 4:00pm |
-1 |
Every failure to error check. |
1 |
Server prints the IP number of the server. |
1 |
Can check one port. |
1 |
Can check ports 1 .. 99. |
1 |
Output matches the format above EXACTLY. |
1 |
Can read the hostname and port range from the command line. |
Hints
My version took 67 lines of code including whitespace.
One
can find the values on the command line like
this.
One can flush cout without printing a carriage
return like this
cout << "HI" <<
flush;
Some people have found the following code useful
int
MakeSocket(char *host, int port) {
int s;
int len;
struct sockaddr_in sa;
struct hostent *hp;
struct servent *sp;
int portnum;
int
ret;
hp
= gethostbyname(host);
if (hp == 0) {
perror("HP");
exit(1);
}
bcopy((char *)hp->h_addr, (char
*)&sa.sin_addr, hp->h_length);
sa.sin_family = hp->h_addrtype;
sa.sin_port = htons(port);
s = socket(hp->h_addrtype, SOCK_STREAM,
0);
ret
= connect(s, (struct sockaddr *)&sa, sizeof(sa));
return ret;
}