Skip to content

Viraj-Ganguli/Go-Port-Scanner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go-PortScanner

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.


Features

  • 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

Project Structure

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

Installation

Prerequisites

  • Go 1.18+ installed
  • (Optional) Python 3.8+ if you want to run the fake banner test server

Clone the repository

git clone https://github.com/yourusername/go-portscanner.git
cd go-portscanner

Build the scanner

go build -o portscanner main.go

Usage

Syntax

./portscanner <host> <start_port> <end_port>

Example

./portscanner 127.0.0.1 20 1000

Example output

Port 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

How It Works

  1. main.go parses command-line arguments and validates the port range using utils.ValidatePortRange.

  2. scanner.ScanPorts runs concurrent TCP connection attempts with a 1-second timeout.

  3. For each successful connection, banners.GrabBanner attempts 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.
  4. The scanner prints open ports and any banners captured.


Testing with the Fake Banner Server

You can test locally using the included Python script.

Start the fake server

python3 test_server/fake_services.py

This script opens multiple local ports (e.g., 21, 22, 80, 8080) and responds with simulated banners.

Run the scanner

./portscanner 127.0.0.1 20 10000

The scanner should detect and print the simulated services.


Disclaimer

This tool is for educational and authorized testing purposes only. Do not use it to scan systems without explicit permission.


Future Enhancements

  • Add UDP scanning support
  • Implement JSON/CSV output formatting
  • Add progress indicators or scan rate limits
  • Improve service detection using signature matching

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors