Added simple-port-scanner exercise!

This commit is contained in:
raul 2024-10-13 21:12:58 +02:00
parent 1e08dc4069
commit cd17d47e0d
2 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,3 @@
module simple-port-scanner
go 1.23.2

View File

@ -0,0 +1,35 @@
package main
import (
"fmt"
"log"
"net"
"os"
)
var (
IP string
Port string
ScanType = "tcp"
)
func main() {
if len(os.Args) != 3 {
fmt.Printf("Insufficient arguments:\n./simple-port-scanner $IP $PORT")
os.Exit(0)
}
IP = os.Args[1]
Port = os.Args[2]
fmt.Printf("Scanning %v:%v...\n", IP, Port)
conn, err := net.Dial(ScanType, IP+":"+Port)
if err != nil {
log.Fatalf("Fatal error occurred while scanning port: %v\n", err)
}
defer conn.Close()
}
func handleConn(conn net.Conn) {
}