Creating a simple port scanner using libnet and libpcap together
In Chapter 3, Using Libnet, we discussed how to use libnet to inject packets into the network. In this chapter, we discussed how to use libpcap to capture and analyze the incoming packets. The next logical question is, "How can we use libnet and libpcap to create some really awesome network security tools?" This recipe is written to show you how we can use libnet and libpcap together.
We will build a simple port scanner that scans a range of ports on a remote device and lists whether that port is open or closed. We will implement a SYN scan. This is a scan that sends a packet with the SYN flag set, and if the port is open, the remote device will respond with a packet that has the SYN and ACK flags set. If the port is not open, the remote device will respond with a packet that has the RST flag set.
We will not go into the technical details of how libpcap and libnet work because that was covered in this chapter and in Chapter 3...