ip_util

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckConnect

func CheckConnect(peerIP string, tryCount int) bool

func FlushAddr

func FlushAddr(iface string) error

only for linux

func GetAllowedIP

func GetAllowedIP(ip string) (*net.IPNet, error)

The allowed IPv4 for clients to be added to the server may only be a /32, but wgctrl expects a list. This function returns the list with a single entry from an IP string. ip=192.0.2.0 ip=192.0.2.0/24

func GetAllowedIPAsStr

func GetAllowedIPAsStr(ip string) (string, error)

ip=192.0.2.0/24 ip=192.0.2.0 maybe just return the same value as input, so we can call this is a validation func

func GetAllowedIPs

func GetAllowedIPs(ips string) ([]net.IPNet, error)

ips=192.0.2.0/24,10.0.0.1/24 ips=192.0.2.0,10.0.0.1/24 ips=192.0.2.0,10.0.0.1

func GetAllowedIPsAsStr

func GetAllowedIPsAsStr(cidrIPs string) (string, error)

cidrIPs=192.0.2.0/24,10.0.0.1/24 maybe just return the same value as input, so we can call this is a validation func

func GetAvailableIP

func GetAvailableIP(ips []string, cidr string) (string, *net.IPNet, error)

This function accepts a list of strings and returns the next IP not in this list. If we overflow the server CIDR, an error is returned.

func GetEndpoint

func GetEndpoint(endpoint string) *net.UDPAddr

endpoint=10.0.0.1:24

func GetIpCidrString

func GetIpCidrString(ip string, cidr string) (string, error)

Accepts an IP and a CIDR as strings and returns a string merging the two.

func GetPeerIP

func GetPeerIP(peerCidrIP string, myCidrIP string) string

if peerIP not empty return peerId, otherwise return the first ip of my ip subnet

func GetSubnetFirstIP

func GetSubnetFirstIP(ip string) string

func IpStringToPrefix

func IpStringToPrefix(ip string) []netip.Prefix

func IterIP

func IterIP(ip net.IP) net.IP

Increments an IP, skipping broadcast addresses.

func ParseCidrIP

func ParseCidrIP(cidrIP string) (net.IP, *net.IPNet, error)

func PingAddr

func PingAddr(addr string) error

func PingOnce

func PingOnce(peerIP string) bool

Types

type IpFunc

type IpFunc func() string

type Pinger

type Pinger struct {
	// contains filtered or unexported fields
}

func NewPinger

func NewPinger(interval int, enable bool, ipFunc IpFunc) *Pinger

func (*Pinger) Enable

func (p *Pinger) Enable()

func (*Pinger) Start

func (p *Pinger) Start()

func (*Pinger) Stop

func (p *Pinger) Stop()

Jump to

Keyboard shortcuts

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