ncutils

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: Apache-2.0 Imports: 22 Imported by: 2

Documentation

Overview

Package ncutils contains utility functions

Index

Constants

View Source
const DefaultGCPercent = 10

DefaultGCPercent - garbage collection percent

View Source
const KeySize = 2048

KeySize = ideal length for keys

View Source
const MaxNameLength = 62

MaxNameLength - maximum node name length

View Source
const NetclientDefaultPort = 51821

NetclientDefaultPort - default port

View Source
const NoDBRecord = "no result found"

NoDBRecord - error message result

View Source
const NoDBRecords = "could not find any records"

NoDBRecords - error record result

View Source
const PidFile = "/var/run/netclient.pid"

PidFile - path/name of pid file

View Source
const WindowsSvcName = "netclient"

WindowsSvcName - service name

Variables

This section is empty.

Functions

func CheckFirewall

func CheckFirewall()

CheckFirewall - checks if iptables of nft install, if not exit

func CheckIPAddress

func CheckIPAddress(ip string) error

func CheckWG

func CheckWG()

CheckWG - Checks if WireGuard is installed. If not, exit

func ConvHostPassToHash added in v0.20.5

func ConvHostPassToHash(hostPass string) string

ConvHostPassToHash - converts password to md5 hash

func ConvertBytesToKey

func ConvertBytesToKey(data []byte) (*[32]byte, error)

ConvertBytesToKey - util to convert bytes to a key to use elsewhere

func ConvertKeyToBytes

func ConvertKeyToBytes(key *[32]byte) ([]byte, error)

ConvertKeyToBytes - util to convert a key to bytes to use elsewhere

func Copy

func Copy(src, dst string) error

Copy - copies a src file to dest

func DNSFormatString

func DNSFormatString(input string) string

DNSFormatString - Formats a string with correct usage for DNS

func FileExists

func FileExists(f string) bool

FileExists - checks if file exists locally

func GetEmbedded

func GetEmbedded() error

GetEmbedded - if files required for linux, put here

func GetFileAsString

func GetFileAsString(path string) (string, error)

GetFileAsString - returns the string contents of a given file

func GetFileWithRetry

func GetFileWithRetry(path string, retryCount int) ([]byte, error)

GetFileWithRetry - retry getting file X number of times before failing

func GetFreePort

func GetFreePort(rangestart int) (int, error)

GetFreePort - gets free port of machine

func GetFreeTCPPort added in v0.19.0

func GetFreeTCPPort() (string, error)

GetFreeTCPPort - gets free TCP port

func GetHomeDirWindows

func GetHomeDirWindows() string

GetHomeDirWindows - gets home directory in windows

func GetHostname

func GetHostname() string

GetHostname - Gets hostname of machine

func GetIPNetFromString

func GetIPNetFromString(ip string) (net.IPNet, error)

func GetInterfaceName

func GetInterfaceName() string

GetInterfaceName - fetches the interface name

func GetLocalIP

func GetLocalIP(localrange net.IPNet) (*net.IPNet, error)

GetLocalIP - gets local ip of machine returns first interface that is up, is not a loopback and is

func GetMacAddr

func GetMacAddr() ([]net.HardwareAddr, error)

GetMacAddr - get's mac address

func GetNetworkIPMask

func GetNetworkIPMask(networkstring string) (string, string, error)

GetNetworkIPMask - Pulls the netmask out of the network

func GetNewIface

func GetNewIface(dir string) (string, error)

GetNewIface - Gets the name of the real interface created on Mac

func GetPublicIP

func GetPublicIP(api string) (net.IP, error)

GetPublicIP - gets public ip

func GetPublicIPv6 added in v0.24.0

func GetPublicIPv6() (net.IP, error)

GetPublicIPv6 - gets public ipv6 address

func GetSeparator

func GetSeparator() string

GetSeparator - gets the separator for OS

func GetWireGuard

func GetWireGuard() string

GetWireGuard - checks if wg is installed

func HasWG

func HasWG() bool

HasWG - returns true if wg command exists

func HasWgQuick

func HasWgQuick() bool

HasWgQuick - checks if WGQuick command is present

func IPIsPrivate

func IPIsPrivate(ipnet net.IP) bool

func InterfaceExists added in v0.22.0

func InterfaceExists(ifaceName string) (bool, error)

InterfaceExists - checks if iface exists already

func IsBridgeNetwork added in v0.18.6

func IsBridgeNetwork(ifaceName string) bool

IsBridgeNetwork - check if the interface is a bridge type

func IsEmptyRecord

func IsEmptyRecord(err error) bool

IsEmptyRecord - repeat from database

func IsFreeBSD

func IsFreeBSD() bool

IsFreeBSD - checks if is freebsd

func IsIPTablesPresent

func IsIPTablesPresent() bool

IsIPTablesPresent - returns true if iptables is present, false otherwise Does not consider OS, up to the caller to determine if the OS supports iptables/whether this check is valid.

func IsKernel

func IsKernel() bool

IsKernel - checks if running kernel WireGuard

func IsLinux

func IsLinux() bool

IsLinux - checks if is linux

func IsMac

func IsMac() bool

IsMac - checks if is a mac

func IsNFTablesPresent

func IsNFTablesPresent() bool

IsNFTablesPresent - returns true if nftables is present, false otherwise. Does not consider OS, up to the caller to determine if the OS supports nftables/whether this check is valid.

func IsPortFree added in v0.21.0

func IsPortFree(port int) (free bool)

IsPortFree - checks if port is free

func IsWindows

func IsWindows() bool

IsWindows - checks if is windows

func RandomMacAddress added in v0.18.5

func RandomMacAddress() net.HardwareAddr

RandomMacAddress returns a random macaddress

func RandomString added in v0.20.5

func RandomString(length int) string

RandomString - returns a random string in a charset

func ReadPID

func ReadPID() (int, error)

ReadPID - reads a previously saved pid from disk

func RunCmd

func RunCmd(command string, printerr bool) (string, error)

RunCmd - runs a local command

func RunCmdFormatted

func RunCmdFormatted(command string, printerr bool) (string, error)

RunCmdFormatted - does nothing for linux

func RunCmds

func RunCmds(commands []string, printerr bool) error

RunCmds - runs cmds

func SavePID

func SavePID() error

SavePID - saves the pid of running program to disk

func ServerAddrSliceContains

func ServerAddrSliceContains(slice []models.ServerAddr, item models.ServerAddr) bool

ServerAddrSliceContains - sees if a string slice contains a string element

func SetInterfaceName added in v0.22.0

func SetInterfaceName(iface string)

func ShortenString

func ShortenString(input string, length int) string

ShortenString - Brings string down to specified length. Stops names from being too long

Types

type WindowsPIDError

type WindowsPIDError struct{}

WindowsPIDError - error returned from pid function on windows

func (*WindowsPIDError) Error

func (*WindowsPIDError) Error() string

Error generates error for windows os

Jump to

Keyboard shortcuts

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