Your challenge is to write a port scanner in Go that uses a worker pool to efficiently scan multiple ports concurrently. It should meet the following requirements:
- Accepts a range of ports to scan as an argument (e.g. ./portscan -ports 8080-9090)
- Accepts a number of workers to use for performing the scans (e.g. ./portscan -workers 100)
- Outputs
<PORT> CLOSED
for closed ports as they are discovered. - Outputs
<PORT> OPEN
for open ports as they are discovered. - Extra credit: How could you informed the user of your port scanner of the likely service running on the open ports? (e.g. 5432 is likely a PostgreSQL server)
Hints:
- Use the
flags
package to capture invocation parameters. - Rely on the
net
package. - Make use of channels for communication across goroutines.