netports

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2025 License: MIT Imports: 4 Imported by: 0

README

TCP and UDP port numbers

Well known ports parsed from https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers

ports.json - JSON array file with all ports parsed from Wikipedia in format:

type Port struct {
    // Start
    // Port number range start and end. Single port is represented as [port, port], i.e. {22, 22}
    // multiple ports are represented as [min, max] included, i.e. {2001, 2009}
    Start uint16 `json:"start"`
    End   uint16 `json:"end"`

    Category    PortCategory `json:"category"`
    Description string       `json:"description"`

    Types map[PortProto]RegistrationStatus `json:"types"`
}

Usage

# Install
go get github.com/teadove/netports
package main

import "github.com/teadove/netports"

func main(){
    fmt.Printf("%+v\n", netports.KnownPorts()[0])
}

Documentation

Overview

Package netports Well known ports parsed from https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Filter

type Filter func(Port) bool

func FilterByCategory

func FilterByCategory(categories ...PortCategory) Filter

func FilterByProto

func FilterByProto(proto PortProto) Filter

type Port

type Port struct {
	// Start
	// Port number range start and end. Single port is represented as [port, port], i.e. {22, 22}
	// multiple ports are represented as [min, max] included, i.e. {2001, 2009}
	Start uint16 `json:"start"`
	End   uint16 `json:"end"`

	Category    PortCategory `json:"category"`
	Description string       `json:"description"`

	Types map[PortProto]RegistrationStatus `json:"types"`
}

type PortCategory

type PortCategory string
const (
	// CategoryWellKnown (0-1024).
	CategoryWellKnown PortCategory = "WellKnown"
	// CategoryRegistered (1024-49151).
	CategoryRegistered PortCategory = "Registered"
	// CategoryOther (49152-65535).
	CategoryOther PortCategory = "Other"
)

type PortProto

type PortProto string
const (
	TCP  PortProto = "tcp"
	UDP  PortProto = "udp"
	SCTP PortProto = "sctp"
	DCCP PortProto = "dccp"
)

type Ports

type Ports []Port
Example
fmt.Printf("%d %d",
	len(KnownPorts.FilterCollect(
		FilterByProto(TCP),
		FilterByCategory(CategoryWellKnown, CategoryRegistered),
	)),
	len(KnownPorts.FilterCollect(
		FilterByProto(UDP),
		FilterByCategory(CategoryWellKnown, CategoryRegistered),
	)),
)
Output:

2853 2448
var KnownPorts Ports

KnownPorts List of known ports from https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers

func (Ports) Filter

func (r Ports) Filter(callbacks ...Filter) iter.Seq[Port]

func (Ports) FilterCollect

func (r Ports) FilterCollect(callbacks ...Filter) Ports

func (Ports) GroupByNumber

func (r Ports) GroupByNumber() map[uint16]Ports

type RegistrationStatus

type RegistrationStatus string
const (
	// RegistrationYes
	// Described protocol is assigned by IANA for this port, and is: standardized, specified, or widely used for such.
	RegistrationYes RegistrationStatus = "Yes"
	// RegistrationUnofficial
	// Described protocol is not assigned by IANA for this port, but is: standardized, specified, or widely used for such.
	RegistrationUnofficial RegistrationStatus = "Unofficial"
	// RegistrationAssigned
	// Described protocol is assigned by IANA for this port, but is not: standardized, specified, or widely used for such.
	RegistrationAssigned RegistrationStatus = "Assigned"
	// RegistrationNo
	// Described protocol is not assigned by IANA for this port, standardized, specified, or widely used for such.
	RegistrationNo RegistrationStatus = "No"
	// RegistrationReserved
	// Port is reserved by IANA, generally to prevent collision having its previous use removed.
	// The port number may be available for assignment upon request to IANA.
	RegistrationReserved RegistrationStatus = "Reserved"
)

Jump to

Keyboard shortcuts

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