A lightweight, concurrent TCP port scanner written in Go with optional banner grabbing support to identify running services. Includes a companion Python test server that emulates common network services for testing and demonstration.
- Concurrent scanning of port ranges for improved speed
- Banner grabbing for service identification (e.g., SSH, HTTP, SMTP)
- Timeout handling to prevent indefinite blocking
- Port range validation for safety and correctness
- Uses only the Go standard library
go-portscanner/
├── main.go # Entry point — parses args and runs the scan
├── scanner/
│ └── scanner.go # Handles concurrent TCP port scanning
├── banners/
│ └── banners.go # Implements banner grabbing for open ports
├── utils/
│ └── utils.go # Provides input validation utilities
└── test_server/
└── fake_services.py # Python test script to simulate network services
- Go 1.18+ installed
- (Optional) Python 3.8+ if you want to run the fake banner test server
git clone https://github.com/yourusername/go-portscanner.git
cd go-portscannergo build -o portscanner main.go./portscanner <host> <start_port> <end_port>./portscanner 127.0.0.1 20 1000Port 21 open: "220 FTP Server ready"
Port 22 open: "SSH-2.0-OpenSSH_8.0"
Port 80 open: "HTTP/1.1 200 OK"
Open ports on 127.0.0.1:
- 21
- 22
- 80
-
main.goparses command-line arguments and validates the port range usingutils.ValidatePortRange. -
scanner.ScanPortsruns concurrent TCP connection attempts with a 1-second timeout. -
For each successful connection,
banners.GrabBannerattempts to read a service banner:- For ports 80 and 8080, an HTTP GET request is sent first.
- The function reads up to the first newline from the service response.
-
The scanner prints open ports and any banners captured.
You can test locally using the included Python script.
python3 test_server/fake_services.pyThis script opens multiple local ports (e.g., 21, 22, 80, 8080) and responds with simulated banners.
./portscanner 127.0.0.1 20 10000The scanner should detect and print the simulated services.
This tool is for educational and authorized testing purposes only. Do not use it to scan systems without explicit permission.
- Add UDP scanning support
- Implement JSON/CSV output formatting
- Add progress indicators or scan rate limits
- Improve service detection using signature matching