net

package
v0.0.0-...-9cf5c93 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2018 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RangeWithoutNetworkNumber drops the network number (the first address)
	RangeWithoutNetworkNumber = iota + 1
	// RangeWithoutBroadcast drops the broadcast address (the last address)
	RangeWithoutBroadcast
)

Variables

View Source
var (
	// ErrMixedIPVersion presents an error while trying to compute IPv4
	// with IPv6.
	ErrMixedIPVersion = errors.New("IPv4 and IPv6 can not be computed together")
)

Functions

This section is empty.

Types

type Network

type Network struct {
	Subnets []*Subnet
}

Network is an IP network which can combine multiple subnets inside.

func NewNetwork

func NewNetwork(subnet ...*Subnet) *Network

NewNetwork intializes a new network with given subnets.

func (*Network) Range

func (in *Network) Range(opts ...RangeOption) (ips []net.IP)

Range returns all available IP addresses in the network, which also includes the network number (the first) and the broadcast address (the last).

func (*Network) RangeString

func (in *Network) RangeString(opts ...RangeOption) (ips []string)

RangeString returns all available IP addresses as a string array in the network, which also includes the network number (the first) and the broadcast address (the last).

type PortScanner

type PortScanner interface {
	Scan(ctx context.Context, hostports ...string) ([]PortStatus, error)
}

PortScanner is the generic interface of port scanner

func NewTCPPortScanner

func NewTCPPortScanner() PortScanner

NewTCPPortScanner returns a new TCPPortScanner as PortScanner.

type PortStatus

type PortStatus struct {
	// Host represents the host address or its DNS hostname.
	Host string
	// The RemoteAddr while scanning on remote host. For TCPPortScanner, its type
	// should be *net.TCPAddr.
	Addr net.Addr
	// Indicates whether the port is open.
	Opened bool
}

PortStatus is the scanning result of a single host.

type RangeOption

type RangeOption uint8

RangeOption is the option to use within range

type Subnet

type Subnet struct {
	// contains filtered or unexported fields
}

Subnet is a subset of IP network.

func NewSubnet

func NewSubnet(cidr string) (subnet *Subnet, err error)

NewSubnet initialize a new subnet with given `cidr`, returns encountered error if any.

func (*Subnet) CIDR

func (in *Subnet) CIDR() *net.IPNet

CIDR returns the subnet's standard CIDR as net.IPNet.

func (*Subnet) Range

func (in *Subnet) Range(opts ...RangeOption) (ips []net.IP)

Range returns all available IP addresses in the subnet, which also includes the network number (the first) and the broadcast address (the last).

func (*Subnet) RangeString

func (in *Subnet) RangeString(opts ...RangeOption) (ips []string)

RangeString returns all available IP addresses as a string array in the subnet, which also includes the network number (the first) and the broadcast address (the last).

type TCPPortScanner

type TCPPortScanner struct {
	ScanFn func(ctx context.Context, hostports ...string) ([]PortStatus, error)
	// contains filtered or unexported fields
}

TCPPortScanner is used for

func (*TCPPortScanner) Scan

func (in *TCPPortScanner) Scan(ctx context.Context, hostports ...string) ([]PortStatus, error)

Scan implements the Scan method of PortScanner. To change its default behavior, you can override the ScanFn with your own implementation.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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