addrx

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2025 License: MIT Imports: 8 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Addrs

func Addrs() ([]net.Addr, error)

Addrs returns a list of unicast interface addresses for all interface.

func ClientIP

func ClientIP(r *http.Request) string

ClientIP 尽最大努力实现获取客户端 IP 的算法。 解析 X-Real-IP 和 X-Forwarded-For 以便于反向代理(nginx 或 haproxy)可以正常工作。

func ClientPublicIP

func ClientPublicIP(r *http.Request) string

ClientPublicIP 尽最大努力实现获取客户端公网 IP 的算法。 解析 X-Real-IP 和 X-Forwarded-For 以便于反向代理(nginx 或 haproxy)可以正常工作。

func GlobalUnicastAddr

func GlobalUnicastAddr(address net.Addr) (net.IP, int, error)

func GlobalUnicastIPString

func GlobalUnicastIPString() (string, error)

GlobalUnicastIPString get a global unicast IP address string

func GlobalUnicastIPs

func GlobalUnicastIPs() ([]net.IP, error)

GlobalUnicastIPs returns a list of global unicast IPs for all interface.

func IP2Long

func IP2Long(ip net.IP) (uint, error)

IP2Long 把net.IP转为数值

func IPString2Long

func IPString2Long(ip string) (uint, error)

IPString2Long 把ip字符串转为数值

func IPs

func IPs() ([]net.IP, error)

IPs returns a list of IPs for all interface.

func InterfaceIPs

func InterfaceIPs(name string) ([]net.IP, error)

InterfaceIPs get public IP addresses by interface name

func InterfaceIPv4

func InterfaceIPv4(name string) ([]net.IP, error)

InterfaceIPv4 get a public IPv4 address

func IsGlobalUnicastIP

func IsGlobalUnicastIP(ip net.IP) bool

IsGlobalUnicastIP check whether the IP is a global unicast IP

func IsLocalIP

func IsLocalIP(ip net.IP) bool

IsLocalIP 检测 IP 地址是否是内网地址 通过直接对比ip段范围效率更高

func IsLocalIPAddr

func IsLocalIPAddr(ip string) bool

IsLocalIPAddr 检测 IP 地址字符串是否是内网地址

func Long2IP

func Long2IP(i uint) (net.IP, error)

Long2IP 把数值转为net.IP

func Long2IPString

func Long2IPString(i uint) (string, error)

Long2IPString 把数值转为ip字符串

func PickFreePort

func PickFreePort() (int, error)

PickFreePort automatically chose a free port and return it

func RemoteIP

func RemoteIP(r *http.Request) string

RemoteIP 通过 RemoteAddr 获取 IP 地址, 只是一个快速解析方法。

func SplitHostPort

func SplitHostPort(addr net.Addr) (net.IP, int, error)

SplitHostPort splits a network address of the form net.Addr,

Types

This section is empty.

Jump to

Keyboard shortcuts

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