net

package
v0.0.0-...-d92ecab Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package net is the main module to handle all network-related metadata collection actions.

It is capable of running each module individually (except port scan, which requires a ping scan), where the absense of data will simply return an empty object corresponding to that module (PingScan, HostScan, or the whole net object).

Its main focus is the Network.Build() method, responsible for queueing and orchestrating all the network-related tasks, but it also contains the PingScan.ExpandCIDR() method, which is responsible for breaking down subnets into slices of strings, for the respective hosts in it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alive

type Alive struct {
	Address string        `json:"addr"`
	Time    time.Duration `json:"rtt"`
}

Alive struct will contain each responding element returned in the ping scan

type HostScan

type HostScan struct {
	Target   string `json:"target"`
	Protocol string `json:"proto"`
	Ports    []int  `json:"ports"`
}

HostScan struct will contain the probe results for a single host. It will hold the target IP address, the protocol used, and the open ports in a slice of ints.

func (*HostScan) New

func (h *HostScan) New(s *ScanResults, scanScope int) *HostScan

New method (HostScan) will initiate a new wave of PortScan.New() events for the range defined in the scanScope parameter a quick scan would probe 1024 ports while a wide scan would target 49152 ports

type Network

type Network struct {
	System System     `json:"sys"`
	Ping   PingScan   `json:"ping"`
	Ports  []HostScan `json:"ports"`
}

Network type will be converted to JSON containing important information for this module

func (*Network) Build

func (n *Network) Build(netRef, pingRef string, slowPing, portScanOpt bool) *Network

Build method - issues network-related microprocesses which builds up to the Network struct

type PingScan

type PingScan struct {
	Target string  `json:"target"`
	Alive  []Alive `json:"alive"`
}

PingScan struct will contain the ping results from the last scan

func (*PingScan) Burst

func (p *PingScan) Burst(mwg *sync.WaitGroup, addr []string) *PingScan

Burst method - will take advantage of goroutines to issue all ping requests concurrently Go will automatically manage this sequence, which is aimed for performance, not order

func (*PingScan) ExpandCIDR

func (p *PingScan) ExpandCIDR(target string) ([]string, error)

ExpandCIDR method - expands (simple) CIDR addresses taking the example from https://gist.github.com/kotakanbe/d3059af990252ba89a82 Fixed issue with /32 CIDR addresses

func (*PingScan) Get

func (p *PingScan) Get() []string

Get method will return the slice of addresses (strings) for all alive hosts. This is being used on the port scan routines, to skip running through all addresses again

func (*PingScan) New

func (p *PingScan) New(wg *sync.WaitGroup, ct int, t time.Duration, h string)

New method - issues a new ping event to the provided address, while building the PingScan.Alive struct with its results

func (*PingScan) Paced

func (p *PingScan) Paced(mwg *sync.WaitGroup, addr []string) *PingScan

Paced method - similar to Burst method, but with no goroutines. This will result in a slower, one-by-one ping execution, where the results will come back indexed as sent

type PortScan

type PortScan struct {
	Port   int    `json:"port"`
	Status string `json:"status"`
}

PortScan struct will contain the results for a single port scan. The Port key will contain an int with the port while the Open key will contain a boolean for open / closed status

func (*PortScan) New

func (p *PortScan) New(h *HostScan, port int) *PortScan

New method (PortScan) will initiate a new set of PortScan.Scan() events, and register only the open ports in the HostScan.Ports[] slice of ints

func (*PortScan) Scan

func (p *PortScan) Scan(proto, addr string, port int) *PortScan

Scan method will dial in for the referred {host}:{port} with a 10-second timeout. The `return` statements will allow for continuously probe for open/closed ports without falling back on an error

type Scan

type Scan interface {
	Burst(addr string) *PingScan
	Paced(addr string) *PingScan
}

Scan interaface will list the different ping options possible when using the tool

type ScanResults

type ScanResults struct {
	Results []HostScan `json:"results"`
}

ScanResults struct will hold a list of HostScans. This is the placeholder for all host queries

func (*ScanResults) Create

func (s *ScanResults) Create(mwg *sync.WaitGroup, hosts []string, scanScope int) *ScanResults

Create method will initialize a set of HostScan.New() events, based on the provided hosts, which are being fed as a slice of strings.

type System

type System struct {
	Device     string `json:"device"`
	ID         int    `json:"id"`
	IPAddress  string `json:"ipv4"`
	SubnetMask string `json:"mask"`
}

System type will contain this device's network information

func (*System) Get

func (s *System) Get(wg *sync.WaitGroup, ipDevice string) *System

Get method - runs a simple `ip` command to retrieve the current information from the active network device, which returns a pointer to the Internet struct with this data

Jump to

Keyboard shortcuts

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