net

package
v0.5.9 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2024 License: Apache-2.0 Imports: 9 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PrivateNetworks = []net.IPNet{
	MustParseCIDR("10.0.0.0/8"),
	MustParseCIDR("172.16.0.0/12"),
	MustParseCIDR("192.168.0.0/16"),
	MustParseCIDR("127.0.0.0/8"),
	MustParseCIDR("0.0.0.0/8"),
	MustParseCIDR("169.254.0.0/16"),
	MustParseCIDR("192.0.0.0/24"),
	MustParseCIDR("192.0.2.0/24"),
	MustParseCIDR("198.51.100.0/24"),
	MustParseCIDR("203.0.113.0/24"),
	MustParseCIDR("192.88.99.0/24"),
	MustParseCIDR("192.18.0.0/15"),
	MustParseCIDR("224.0.0.0/4"),
	MustParseCIDR("240.0.0.0/4"),
	MustParseCIDR("255.255.255.255/32"),
	MustParseCIDR("100.64.0.0/10"),
	MustParseCIDR("::/128"),
	MustParseCIDR("::1/128"),
	MustParseCIDR("100::/64"),
	MustParseCIDR("2001::/23"),
	MustParseCIDR("2001:2::/48"),
	MustParseCIDR("2001:db8::/32"),
	MustParseCIDR("2001::/32"),
	MustParseCIDR("fc00::/7"),
	MustParseCIDR("fe80::/10"),
	MustParseCIDR("ff00::/8"),
	MustParseCIDR("2002::/16"),
}

PrivateNetworks net.IPNets that are loopback, private, link local, default unicast based on https://github.com/letsencrypt/boulder/blob/master/bdns/dns.go

Functions

func BaseURL

func BaseURL(r *http.Request) (baseUrl string)

func CheckRequestIpWithList

func CheckRequestIpWithList(req *http.Request, list []string) bool

CheckRequestIpWithList returns TRUE if the remote IP in an http.Request is from an IP in the given list of CIDR ranges

func Download

func Download(url, path string) (err error)

func Get

func Get(url string) (content string, err error)

func GetIpFromRequest

func GetIpFromRequest(r *http.Request) (ip string, err error)

func GetProxyIpFromRequest

func GetProxyIpFromRequest(r *http.Request) (ip string, err error)

func GetRemoteAddr

func GetRemoteAddr(r *http.Request) (ip string)

func Hostname

func Hostname() string

func IsIpInRange

func IsIpInRange(ip string, cidr string) bool

func IsNetIpInRange

func IsNetIpInRange(ip net.IP, cidr string) bool

func IsNetIpPrivate

func IsNetIpPrivate(ip net.IP) (private bool)

IsNetIpPrivate returns true if the IP address given is within any of the local or private network CIDR ranges (not public IP address space)

func MakeUrl added in v0.1.0

func MakeUrl(path string, r *http.Request) (url string)

func MustParseCIDR

func MustParseCIDR(s string) net.IPNet

MustParseCIDR parses string into net.IPNet

func ParseCIDR added in v0.5.0

func ParseCIDR(input ...string) (cidrs []*net.IPNet, err error)

func ParseIP added in v0.5.0

func ParseIP(input ...string) (ips []net.IP, err error)

func ParseIpFromRequest

func ParseIpFromRequest(r *http.Request) (ip net.IP, err error)

Types

This section is empty.

Directories

Path Synopsis
ip

Jump to

Keyboard shortcuts

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