network

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Address.Type (nmap `addrtype` attribute).
	AddrTypeIPv4 = "ipv4"
	AddrTypeIPv6 = "ipv6"
	AddrTypeMAC  = "mac"

	// Port.Protocol / Service.Protocol (nmap `proto` attribute).
	ProtoTCP  = "tcp"
	ProtoUDP  = "udp"
	ProtoSCTP = "sctp"
)

Address types and transport protocols.

These are NOT an enum: the values are the exact strings nmap writes into its XML `addrtype`/`proto` attributes (Address.Type, Port.Protocol/Service.Protocol), unmarshalled straight into the `string` fields via their `xml:"…"` tags. They are therefore an external contract whose spelling must not drift — these consts give the codebase one authoritative spelling to switch/compare against instead of literals duplicated across the network, scan/ingest and cmd packages.

Variables

View Source
var DisplayFields = map[string]func(port *host.Port) string{

	"ID": func(port *host.Port) string {
		id := display.FormatSmallID(port.Id)

		if port.State == nil {
			return id
		}

		switch port.State.State {
		case hostdomain.PortOpen:
			return color.HiGreenString(id)
		case hostdomain.PortFiltered:
			return color.HiYellowString(id)
		case hostdomain.PortClosed:
			return color.HiRedString(id)
		}

		return id
	},
	"Num": func(port *host.Port) string {
		return strconv.Itoa(int(port.Number))
	},
	"Proto": func(port *host.Port) string {
		proto := color.HiBlackString(port.Protocol)

		if port.Service == nil {
			return proto
		} else {
			proto = ""
		}

		if port.Service.Protocol != "" {
			proto += port.Service.Protocol
		} else if port.Service.Name != "" {
			proto += port.Service.Name
		}

		return proto
	},
	"Product": func(port *host.Port) string {
		if port.Service == nil {
			return ""
		}
		product := port.Service.Product
		if port.Service.Version == "" {
			return product
		}
		product += color.HiBlackString(fmt.Sprintf(" (v%s)", port.Service.Version))
		return product
	},
	"Version": func(port *host.Port) string {
		serv := port.Service
		version := port.Service.Version
		if serv.HighVersion != "" && serv.LowVersion != "" {
			version += color.HiBlackString(" (%s / %s)", serv.LowVersion, serv.HighVersion)
		}
		return version
	},
	"Info": func(port *host.Port) string {
		if len(port.Scripts) == 0 {
			return port.Service.ExtraInfo
		}

		var scripts string
		for _, script := range port.Scripts {
			name := script.Name
			if script.Output == "" && script.Name == "" {
				continue
			}
			scripts += fmt.Sprintf("(%s) %s\n", name, script.Output)
		}

		return strings.TrimSuffix(scripts, "\n")
	},
	"Extra Info": func(port *host.Port) string {
		if port.Service == nil {
			return ""
		}
		return port.Service.ExtraInfo
	},
	"Fingerprint": func(port *host.Port) string {
		if port.Service == nil {
			return ""
		}
		return port.Service.ServiceFP
	},

	"Method": func(port *host.Port) string {
		if port.Service == nil {
			return ""
		}
		return color.HiBlackString(port.Service.Method)
	},
	"State": func(port *host.Port) string {
		if port.State == nil {
			return "unknown"
		}

		switch port.State.State {
		case hostdomain.PortOpen:
			return color.HiGreenString(hostdomain.PortOpen)
		case hostdomain.PortFiltered:
			return color.HiYellowString(hostdomain.PortFiltered)
		case hostdomain.PortClosed:
			return color.HiRedString(hostdomain.PortClosed)
		}

		return port.State.State
	},
	"Reason": func(port *host.Port) string {
		if port.State == nil {
			return "undefined"
		}
		return port.State.Reason
	},
	"Scripts": func(port *host.Port) string {
		scripts := ""
		for _, script := range port.Scripts {
			scripts += printScript(script, 0)
		}

		return scripts
	},
}

DisplayFields maps field names to their value generators.

Functions

func Completions

func Completions() []display.Options

Completions returns some columns to be combined into completion candidates and/or their descriptions.

func Detail

func Detail(port *host.Port, hostLabel string) display.Detail

Detail assembles the full `info` view for a single service: the identity banner, the side-by-side info panes, the derived insights, and the NSE scripts as a trailing section. It hands these to the shared display.Detail renderer, so a service's detail view is laid out identically to every other domain's. hostLabel is the owning host's display name (passed in, since a Port doesn't reference its host).

func DisplayDetails

func DisplayDetails() []display.Options

DisplayDetails returns the headers for a detailed service view.

func DisplayHeaders

func DisplayHeaders() []display.Options

DisplayHeaders returns all weighted table headers for a table of services/ports.

func InfoPanes

func InfoPanes(port *host.Port) []display.Pane

InfoPanes groups a port's detail into titled panes (Service / State / Meta) for side-by-side layout via display.Columns, mirroring the credential info view.

func Insights

func Insights(port *host.Port) (lines []string)

Insights returns cross-cutting observations about a single port for the info view: a cleartext protocol warning, and a note when the port is filtered (no confirmed service).

Types

type Address

type Address network.Address

Address - An address somewhere on a network, or on a host. Can be an IPv4/v6 address, a MAC address, or else. This type has fields that are compliant with Nmap scan schemas.

func (*Address) ToORM

func (a *Address) ToORM(ctx context.Context) (network.AddressORM, error)

ToORM - Get the SQL object for the Host.

func (*Address) ToPB

func (a *Address) ToPB() *network.Address

ToPB - Get the Protobuf object for the Host.

type Service

type Service network.Service

Service - A service somewhere on a network. The type has several categories of fields: general information, and Nmap-compliant fields (fingerprints, protocols, banners, versions).

func (*Service) ToORM

func (s *Service) ToORM(ctx context.Context) (network.ServiceORM, error)

ToORM - Get the SQL object for the Service.

func (*Service) ToPB

func (s *Service) ToPB() *network.Service

ToPB - Get the Protobuf object for the Service.

Directories

Path Synopsis
pb
rpc

Jump to

Keyboard shortcuts

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