views:

40

answers:

2

I want to implement a Linux C program to do the following task: it uses FIN scanning to scan all the open ports of a host.

Here's a short description for the FIN scanning(skip if you already know it):Wikipedia: FIN scanning

In FIN scanning, an open port will not respond in any form, while closed port will send back a RST packet. And every computer has 65536 possible ports in total, you know. I've not found some source code which can give me some directions.

And my idea, kind of low efficiency, is like this: the main program iteratively send FIN packet to each port and a thread is in charge of receiving the feedback (RST packet). This thread only works for a period of time, and after the timeout, it exit. After that, the main program will check and determine which ports have not been RST'd yet.

I think a more serious problem of this scheme is it's not reliable enough because the timeout is hard to define. Does anyone can provide a better scheme, please?

+1  A: 

Maybe nmap code can help you

dimba
Thanks for pointing out NMAP. But I'm afraid it's too big. I'll dig into its source code. And any other help will be appreciated.
fwoncn
+1  A: 

nmap already does this.. But I don't think you can really get around doing a timeout based implementation. A couple seconds should suffice, but set a reasonable default and then make it configurable. This is what I did for an arp scanner I wrote once. I didn't use threads, but instead non-blocking pcap, but a threaded solution would have worked just as well.

Jason