nettools

package
v0.3.11 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2024 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProtocolICMP     = 1
	ProtocolIPv6ICMP = 58
)

Variables

View Source
var (
	ErrEmptyResponse        = errEmptyResponse{}
	ErrNoResponseFromRemote = errNoResponseFromRemote{}
	ErrInvalidAddr          = errInvalidAddr{}
	ErrIPv6Unsupported      = errIPv6Unsupported{}

	// ErrNoResponse           = errors.New("no response from target")
	ErrConnectionRefused    = errors.New("connection refused")
	ErrTTLExceeded          = errors.New("ttl exceeded")
	ErrRandomizedMacAddress = errors.New("randomized mac address")

	ErrNoDnsNames = errors.New("no dns names")

	ErrInvalidPortListString = errors.New("invalid port list string")
)
View Source
var DefaultPkg *pkg

Functions

func DNSCheckAllServers

func DNSCheckAllServers(ctx context.Context, target string) (map[string]map[string][]netip.Addr, error)

func FindAddrsOf

func FindAddrsOf(target string) (addrs []netip.Addr, err error)

FindAddrsOf will resolve the A records into netip.Addr's for the given target. If no A records are returned a ErrEmptyResponse error will be returned

func FindFirstAddrOf

func FindFirstAddrOf(target string) (addr netip.Addr, err error)

FindFirstAddrOf will return the netip.Addr of the first A record of the target. If no A records are returned a ErrEmptyResponse error will be returned

func FindHostnameOf

func FindHostnameOf(addr netip.Addr) (string, error)

func GetExternalAddr

func GetExternalAddr(ctx context.Context) (netip.Addr, error)

func GetUserAgent

func GetUserAgent() string

func IsRandomMac

func IsRandomMac(mac net.HardwareAddr) bool

func ScanTcpPorts

func ScanTcpPorts(ctx context.Context, target netip.Addr, options ...portscanRequestOptionFunc) (ports []int, err error)

func SnmpGetInterfaces

func SnmpGetInterfaces(ctx context.Context, addr netip.Addr, options ...snmpRequestOptionFunc) ([]netip.Prefix, error)

func Traceroute4

func Traceroute4(ctx context.Context, target netip.Addr, opts ...Icmp4EchoOption) ([][]Icmp4EchoResponse, error)

func WithArpNoCache

func WithArpNoCache() arpRequestOptionFunc

func WithArpReplyTimeout

func WithArpReplyTimeout(duration time.Duration) arpRequestOptionFunc

func WithPortscanMaxworkers

func WithPortscanMaxworkers(ct int) portscanRequestOptionFunc

func WithPortscanPortlist

func WithPortscanPortlist(list PortList) portscanRequestOptionFunc

func WithPortscanPortlistName

func WithPortscanPortlistName(name string) portscanRequestOptionFunc

func WithPortscanReplyTimeout

func WithPortscanReplyTimeout(duration time.Duration) portscanRequestOptionFunc

func WithSnmpCommunity

func WithSnmpCommunity(community string) snmpRequestOptionFunc

func WithSnmpPort

func WithSnmpPort(port int) snmpRequestOptionFunc

func WithSnmpReplyTimeout

func WithSnmpReplyTimeout(duration time.Duration) snmpRequestOptionFunc

Types

type ArpEntry

type ArpEntry struct {
	Addr netip.Addr
	MAC  net.HardwareAddr
}

func FindHardwareAddrOf

func FindHardwareAddrOf(ctx context.Context, target netip.Addr, options ...arpRequestOptionFunc) (entry ArpEntry, err error)

func FindUsingIfNameHardwareAddrOf

func FindUsingIfNameHardwareAddrOf(ctx context.Context, ifname string, target netip.Addr, options ...arpRequestOptionFunc) (entry ArpEntry, err error)

func SnmpGetArpTable

func SnmpGetArpTable(ctx context.Context, addr netip.Addr, options ...snmpRequestOptionFunc) ([]ArpEntry, error)

type Arper

type Arper interface {
	FindHardwareAddrOf(context.Context, netip.Addr, ...arpRequestOptionFunc) (ArpEntry, error)
	FindUsingIfNameHardwareAddrOf(context.Context, string, netip.Addr, ...arpRequestOptionFunc) (ArpEntry, error)
}

type CertData

type CertData struct {
	CommonName    string
	Version       string
	IsValid       bool
	DaysTilExpire int
	IssuedBy      string
}

type Dnser

type Dnser interface {
	FindFirstAddrOf(string) (netip.Addr, error)
	FindAddrsOf(string) ([]netip.Addr, error)
	FindHostnameOf(netip.Addr) (string, error)
	DNSCheckAllServers(context.Context, string) (map[string]map[string][]netip.Addr, error)
}

type ErrNoResponseW

type ErrNoResponseW struct {
	Target netip.Addr
	OpErr  *net.OpError
	Err    error
}

func (ErrNoResponseW) Error

func (e ErrNoResponseW) Error() string

func (ErrNoResponseW) Unwrap

func (e ErrNoResponseW) Unwrap() error

type Icmp4EchoOption

type Icmp4EchoOption func(*Icmp4EchoOptions)

func I4EWithAllowAllErrors

func I4EWithAllowAllErrors(allow bool) Icmp4EchoOption

func I4EWithBetweenDuration

func I4EWithBetweenDuration(dur time.Duration) Icmp4EchoOption

func I4EWithCount

func I4EWithCount(ct int) Icmp4EchoOption

func I4EWithIcmpID

func I4EWithIcmpID(id int) Icmp4EchoOption

func I4EWithIcmpSeq

func I4EWithIcmpSeq(seq int) Icmp4EchoOption

func I4EWithListenAddress

func I4EWithListenAddress(target netip.Addr) Icmp4EchoOption

func I4EWithPrivileged added in v0.2.0

func I4EWithPrivileged(allow bool) Icmp4EchoOption

func I4EWithReadTimeout

func I4EWithReadTimeout(to time.Duration) Icmp4EchoOption

func I4EWithTTL

func I4EWithTTL(ttl int) Icmp4EchoOption

type Icmp4EchoOptions

type Icmp4EchoOptions struct {
	Privileged      bool
	ListenAddress   netip.Addr
	ReadTimeout     time.Duration
	IcmpID          int
	IcmpSeq         int
	TTL             int
	Count           int
	BetweenDuration time.Duration
	AllowAllErrors  bool
}

type Icmp4EchoResponse

type Icmp4EchoResponse struct {
	Peer    netip.Addr
	Start   time.Time
	Elapsed time.Duration
	Err     error
}

func Icmp4Echo

func Icmp4Echo(ctx context.Context, target netip.Addr, opts ...Icmp4EchoOption) ([]Icmp4EchoResponse, error)

type Icmp4EchoResponseStatistics

type Icmp4EchoResponseStatistics struct {
	Peer         netip.Addr
	Start        time.Time
	TotalPackets int
	TotalElapsed time.Duration
	Mean         time.Duration
	Minimum      time.Duration
	Maximum      time.Duration
	StdDev       time.Duration
	SuccessCount int
	PacketLoss   float64
	Asn          string
	OrgName      string
}

func CalculateIcmp4EchoResponseStatistics

func CalculateIcmp4EchoResponseStatistics(rs []Icmp4EchoResponse) (ret Icmp4EchoResponseStatistics)

type Icmp4Echoer

type Icmp4Echoer interface {
	Icmp4Echo(context.Context, netip.Addr, ...Icmp4EchoOption) ([]Icmp4EchoResponse, error)
}

type Ipifyer

type Ipifyer interface {
	GetExternalAddr(context.Context) (netip.Addr, error)
}

type Nettooler

type Nettooler interface {
	Arper
	Dnser
	Icmp4Echoer
	Ipifyer
	Portscanner
	Snmper
	TLSer
	Utiler
}

type PortList

type PortList int
const (
	InvalidPortList PortList = iota
	AllPorts
	GeneralPorts
	PriviledgedPorts
	CommonPorts
)

func (PortList) String

func (p PortList) String() string

type Portscanner

type Portscanner interface {
	ScanTcpPorts(context.Context, netip.Addr, ...portscanRequestOptionFunc) ([]int, error)
}

type SnmpInfo

type SnmpInfo struct {
	SystemInfo SnmpSystemInfo
	Interfaces []netip.Prefix
	ArpTable   []ArpEntry
}

func FetchSNMPInfo

func FetchSNMPInfo(ctx context.Context, target netip.Addr, options ...snmpRequestOptionFunc) (SnmpInfo, error)

type SnmpSystemInfo

type SnmpSystemInfo struct {
	Description string
	Contact     string
	Name        string
	Location    string
}

func SnmpGetSystemInfo

func SnmpGetSystemInfo(ctx context.Context, target netip.Addr, options ...snmpRequestOptionFunc) (SnmpSystemInfo, error)

type Snmper

type Snmper interface {
	FetchSNMPInfo(context.Context, netip.Addr, ...snmpRequestOptionFunc) (SnmpInfo, error)
	SnmpGetSystemInfo(context.Context, netip.Addr, ...snmpRequestOptionFunc) (SnmpSystemInfo, error)
	SnmpGetInterfaces(context.Context, netip.Addr, ...snmpRequestOptionFunc) ([]netip.Prefix, error)
	SnmpGetArpTable(context.Context, netip.Addr, ...snmpRequestOptionFunc) ([]ArpEntry, error)
}

type TLS

type TLS struct {
	ServerName    string
	CommonName    string
	Version       string
	IsValid       bool
	DaysTilExpire int
	IssuedBy      string
	Chain         []CertData
	TLSData       *tls.ConnectionState
}

func FetchTLS

func FetchTLS(url string) (TLS, error)

type TLSer

type TLSer interface {
	FetchTLS(string) (TLS, error)
}

type Utiler

type Utiler interface {
	IsRandomMac(net.HardwareAddr) bool
	GetUserAgent() string
}

Jump to

Keyboard shortcuts

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