utils

package
v0.2.2-post.2 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2022 License: MIT Imports: 10 Imported by: 0

README

utils

import "github.com/forestvpn/cli/utils"

Index

func ExcludeDisallowedIps

func ExcludeDisallowedIps(allowed []string, disallowed []string) ([]string, error)

ExcludeDisallowedIps is a function that expects two slices of a network values, e.g. [127.0.0.0/8,], where disallowed is a slice of networks to be excluded from the allowed slice. Returns a new slice of networks formed out of the allowed slice without networks of disallowed slice.

func GetActiveSshClientIps

func GetActiveSshClientIps() ([]string, error)

GetActiveSshClientIps is a function that calls the "who" shell command to get active ssh sessions. Then it extracts all the IP addresses from the command output and converts them into networks using ip2Net for a compability with Wiregaurd configuration format. Returns a slice of networks representing the public networks of active ssh clients.

func GetExistingRoutes

func GetExistingRoutes() ([]string, error)

GetExistingRoutes is a function that calls a netstat shell command to get system routing table. Then it extracts all the IP addresses from the shell command's output. Each of an IP addresses is converted into related network using ip2Net in order to be compitable with Wireguard configuration format. Returns a slice of a networks (as a strings) representing system routing table.

func GetHostIP

func GetHostIP() (net.IP, error)

GetHostIP returns the host's public IP address.

See https://github.com/glendc/go-external-ip for more information.

Generated by gomarkdoc

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Verbose bool

Functions

func ExcludeDisallowedIps

func ExcludeDisallowedIps(allowed []string, disallowed []string) ([]string, error)

ExcludeDisallowedIps is a function that expects two slices of a network values, e.g. [127.0.0.0/8,], where disallowed is a slice of networks to be excluded from the allowed slice. Returns a new slice of networks formed out of the allowed slice without networks of disallowed slice.

func GetActiveSshClients

func GetActiveSshClients() ([]string, error)

GetActiveSshClientIps is a function that calls the "who" shell command to get active ssh sessions. Then it extracts all the IP addresses from the command output and converts them into networks using ip2Net for a compability with Wiregaurd configuration format. Returns a slice of networks representing the public networks of active ssh clients.

func GetHttpClient

func GetHttpClient(retries int) *http.Client

GetHttpClient is a factory function to get http client with provided retries number.

func GetLocalTimezone

func GetLocalTimezone() (string, error)

func HumanizeDuration

func HumanizeDuration(duration time.Duration) string

humanizeDuration humanizes time.Duration output to a meaningful value, golang's default “time.Duration“ output is badly formatted and unreadable.

Types

This section is empty.

Jump to

Keyboard shortcuts

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