Adding the Port Scanning Functionality

Learn how to implement the port scanning functionality.

Our application is coming along nicely. We can manage hosts on which to execute a port scan. Let’s implement the port scanning functionality now. Let’s start by adding the functionality to the scan package. After that, we’ll implement the subcommand on the command-line tool.

Creating the scanHosts.go file

We create and edit the file scanHosts.go to hold the code related to the scan functionality. We add the package definition and the import list.

For this functionality, we’ll use:

  • The package fmt for formatted printing.
  • The package net for network-related functions.
  • The package time to define timeouts.

Get hands-on with 1200+ tech skills courses.