I Spy Code - GO

Port Scanner

Here is a simple port scanner written in golang.

Source: (example.go)

package main
 
import (
   "net"
   "fmt"
   "strconv"
)
 
func main() {
 
   for i := 1; i < 65535; i++ {
      port := strconv.FormatInt(int64(i), 10)
      conn, err := net.Dial("tcp", "127.0.0.1:" + port)
      if err == nil {
         fmt.Println("Port",i, "open")
         conn.Close()
      }
   }
}
 

Output:

$ go run example.go
Port 6942 open
Port 63342 open