portscan

package
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 16, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package portscan performs TCP connect scans against one or more ports on a host. It uses only stdlib net.Dial, no raw sockets, no root required, works identically on Linux, macOS, and Windows.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatCompact

func FormatCompact(results []Result) string

FormatCompact renders open ports as "22/ssh 443/https" for terminal display. Falls back to "N/tcp" when the port is not in the IANA registry.

func ParsePorts

func ParsePorts(spec string) ([]int, error)

ParsePorts parses a port specification into a sorted, deduplicated list. Accepts comma-separated ports (22,80,443), ranges (1-1024), or a mix. The empty string and the sentinel "default" both scan all 65535 ports.

Types

type Result

type Result struct {
	Port      int
	Proto     string // always "tcp" for now
	Open      bool
	LatencyMs float64
	IANA      iana.Entry // full IANA record; zero value when port is not in registry
}

Result is the scan outcome for a single port.

func OpenOnly

func OpenOnly(results []Result) []Result

OpenOnly returns only the open results from a scan.

func Scan

func Scan(ctx context.Context, host string, ports []int, timeout time.Duration, concurrency int, db iana.DB) []Result

Scan performs TCP connect probes on host:ports concurrently and returns results sorted by port number. db may be nil (IANA names will be empty). concurrency controls simultaneous dials per call; 0 defaults to 50.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL