netutils

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package netutils provides helper functions for network related operations such as port scanning or subnet slicing.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnrecognizedHostOrIPValue error = errors.New("unrecognized FQDN, single IP Address or range")

ErrUnrecognizedHostOrIPValue indicates that a given string value is unrecognized as a valid FQDN, single IP Address or range (partial or CIDR). This is usually not a temporary error condition.

Functions

func CIDRHosts

func CIDRHosts(cidr string) ([]string, int, error)

CIDRHosts converts a CIDR network pattern into a slice of hosts within that network, the total count of hosts and an error if any occurred.

https://stackoverflow.com/questions/60540465/go-how-to-list-all-ips-in-a-network https://play.golang.org/p/fe-F2k6prlA https://gist.github.com/kotakanbe/d3059af990252ba89a82

func ExpandIPAddress

func ExpandIPAddress(s string) ([]string, error)

ExpandIPAddress accepts a string value representing either an individual IP Address, a CIDR IP range or a partial (dash-separated) range (e.g., 192.168.2.10-15). IP Address ranges and expands to scan for certificates.

func GetCerts

func GetCerts(server string, port int, timeout time.Duration, logger zerolog.Logger) ([]*x509.Certificate, error)

GetCerts retrieves and returns the certificate chain from the specified host & port or an error if one occurs. Enforced certificate verification is intentionally disabled in order to successfully retrieve and examine all certificates in the certificate chain.

func IsCIDR

func IsCIDR(s string) bool

IsCIDR indicates whether a specified string is a CIDR notation IP address and prefix length, like "192.0.2.0/24" or "2001:db8::/32", as defined in RFC 4632 and RFC 4291.

Types

type IPv4AddressOctetsIndex

type IPv4AddressOctetsIndex map[int][]int

IPv4AddressOctetsIndex is a map of IPv4 octets to values within those octets associated with partial ranges. This type is used to help implement support for octet range addressing.

func (IPv4AddressOctetsIndex) IndexSize

func (idx IPv4AddressOctetsIndex) IndexSize() int

IndexSize returns the number of entries in the index.

type PortCheckResult

type PortCheckResult struct {
	IPAddress net.IPAddr
	Port      int
	Open      bool
	Err       error
}

PortCheckResult indicates whether a TCP port is open and what error (if any) occurred checking the port.

func CheckPort

func CheckPort(host string, port int, timeout time.Duration) PortCheckResult

CheckPort checks whether a specified TCP port is open. Any errors encountered are returned along with the port status.

func (PortCheckResult) Summary

func (rs PortCheckResult) Summary() string

Summary generates a one-line summary of port check result.

type PortCheckResults

type PortCheckResults []PortCheckResult

PortCheckResults is a collection of PortCheckResult intended for bulk operations such as filtering or generating summaries.

func (PortCheckResults) HasOpenPort

func (rs PortCheckResults) HasOpenPort() bool

HasOpenPort indicates whether at least one specified port was found to be open for a scanned host.

func (PortCheckResults) Host

func (rs PortCheckResults) Host() string

Host returns the (single) host associated with port check results.

func (PortCheckResults) Summary

func (rs PortCheckResults) Summary() string

Summary generates a one-line summary of port check results.

type PortCheckResultsIndex

type PortCheckResultsIndex map[string]PortCheckResults

PortCheckResultsIndex maps the results slice from scan attempts against a specified list of ports to an IP Address associated with scanned ports.

Jump to

Keyboard shortcuts

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