ports

package
v1.0.18 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2025 License: MPL-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddPortToFile

func AddPortToFile(filePath string, port int, protocol string) error

AddPortToFile adds a port rule to a configuration file

func RemovePortFromFile

func RemovePortFromFile(filePath string, port int) error

RemovePortFromFile removes a port rule from a configuration file

Types

type PortConfig

type PortConfig struct {
	TCPPorts []int            // All TCP ports (from T and B rules)
	UDPPorts []int            // All UDP ports (from U and B rules)
	AllRules []PortRule       // All rules with metadata
	PortMap  map[int][]string // port -> protocols (for deduplication)
}

PortConfig holds all port rules loaded from configuration

func LoadPortsFromDirectory

func LoadPortsFromDirectory(dir string) (*PortConfig, error)

LoadPortsFromDirectory loads all port configuration files from a directory Expected format: PORT/PROTOCOL where PROTOCOL is T (TCP), U (UDP), or B (Both) Example: 22/T, 53/B, 80/T

func LoadPortsFromFile

func LoadPortsFromFile(filePath string) (*PortConfig, error)

LoadPortsFromFile loads port rules from a single configuration file

func (*PortConfig) GetAllPorts

func (c *PortConfig) GetAllPorts() []int

GetAllPorts returns all unique ports regardless of protocol

func (*PortConfig) GetTCPPorts

func (c *PortConfig) GetTCPPorts() []int

GetTCPPorts returns all TCP ports (from T and B rules)

func (*PortConfig) GetUDPPorts

func (c *PortConfig) GetUDPPorts() []int

GetUDPPorts returns all UDP ports (from U and B rules)

type PortRule

type PortRule struct {
	Port     int    // Port number (e.g., 22, 80, 443)
	Protocol string // "T" (TCP), "U" (UDP), or "B" (Both)
	Source   string // Config file where this rule came from
}

PortRule represents a single port rule

Jump to

Keyboard shortcuts

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