portscanner

package module
v0.0.0-...-4ad441c Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2016 License: MIT Imports: 11 Imported by: 0

README

go-portscanner

Port Scanner in golang.

This package implements a basic port scanner. Currently, only TCP Connect scan is implemented. An excutable CLI util can be found in goscan sub directory.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// AllPorts - Convinience var for full port range
	AllPorts = PortRange{1, 65535}
)

Functions

func ExpandCIDR

func ExpandCIDR(cidr string) ([]string, error)

ExpandCIDR - Util function for expanding a CIDR into a list of IPs

func ScanHosts

func ScanHosts(hosts []string, opts ScanOpts, handler ScanResultHandler) error

ScanHosts - Perform scan on a list of hosts. hosts - list of host to scan concurrency - number of simultaneous requests timeout - request timeout for Connect Scan hanlder - port scan result callback, result for each port scanned is passed back in the handler, note that handler can be called concurrently

Types

type HostPortStatus

type HostPortStatus struct {
	Host   string
	Port   int
	Scan   ScanType
	Status PortStatus
}

HostPortStatus - Decriptor for the status of port on a particular host

type HostScanner

type HostScanner struct {
	// Host Address
	Host string
	// Host IP
	IP net.IP
	// Port range to scan
	Range PortRange
	// Throttle for overall concurrency
	Gate chan int
	// RTT Timout
	Timeout time.Duration
	// Use SYNScan instead of Connect Scan for TCP scan
	SYNScan bool
}

HostScanner - struct used to store information needed to scan a particular

host

func NewHostScanner

func NewHostScanner(host string, portRange PortRange) (*HostScanner, error)

NewHostScanner - Create a new scanner for a host host - hostname/ip address portRange - range of ports to scan

func (*HostScanner) Scan

func (hs *HostScanner) Scan(handler ScanResultHandler) error

Scan the ports for the current HostScanner handler - callback for each port scanned

type PortRange

type PortRange struct {
	Start, End int
}

PortRange - Used for specifying a port range

type PortStatus

type PortStatus int

PortStatus - Type for describing Status for a port

const (
	// PSOpen - Port is open
	PSOpen PortStatus = iota
	// PSClose - Port is closed
	PSClose
	// PSTimeout - Port timed out
	PSTimeout
	// PSError - Other errors when trying connect
	PSError
)

func (PortStatus) String

func (ps PortStatus) String() string

type ScanOpts

type ScanOpts struct {
	// Max number of concurrent requests
	Concurrency int
	// Amount of time to wait for a response
	Timeout time.Duration
	// Port Range to scan
	Range PortRange
	// use SYN Scan instead of ConnectScan
	SYNScan bool
}

ScanOpts - struct for aggregating differen scan options

type ScanResultHandler

type ScanResultHandler func(*HostPortStatus)

ScanResultHandler - function type for callback used to handle results

type ScanType

type ScanType int

ScanType - Type of scan

const (
	// ConnectScan - TCP Connect Scan
	ConnectScan ScanType = iota
	// SynScan - TCP SYN Scan
	SynScan
)

func (ScanType) Protocol

func (st ScanType) Protocol() string

Protocol - returns the protocol name in string format for a ScanType

func (ScanType) String

func (st ScanType) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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