net

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2023 License: MIT Imports: 17 Imported by: 1

README

goutils for net utils:

history

GetLocalNS() (NSRecords, error)      
//get local dns config list
func GetGatewayByNic(nicName string) (net.IP, error)    
//return gateway by nicName
func ListGateway() ([]*RouteItem, error) 
//list all gateway of each nic
func GetDefaultGateway() (net.IP, error) 
func IsPublicIP(IP net.IP) bool 
//if an ip is public ip
func GetHostIP() (string, error) 
//get local host ip, like hostname -I
func GetInternalIP() (string, error) {
// get the first ip of nic (will skip loopback)
func GetRequestIP(r *http.Request) string 
// get Request clientIP in http request
func GetInternalIPByDevName(dev string) ([]string, error) {
// get nic ip list by name	
func GetUploadFileSize(upfile multipart.File) (int64, error) {
// get http upload file size
func GetLocalConnectIP(proto string, addr string) (string, error) {
//

Documentation

Overview

utils of network

Index

Constants

View Source
const (
	CACHE_IP_MAX = 64
)

Variables

View Source
var (
	ErrNotFound = errors.New("NOT FOUND")
)

Functions

func GetDefaultGateway

func GetDefaultGateway() (net.IP, error)

func GetExternalIP

func GetExternalIP() (string, error)

返回公网出口IP

func GetGatewayByNic

func GetGatewayByNic(nicName string) (net.IP, error)

func GetHostIP

func GetHostIP() (string, error)

返回主机HOST IP

func GetInternalIP

func GetInternalIP() (string, error)

返回主机内部IP(顺序第一个)

func GetInternalIPByDevName

func GetInternalIPByDevName(dev string) ([]string, error)

根据网卡设备名称返回内部IP

func GetLocalConnectIP

func GetLocalConnectIP(proto string, addr string) (string, error)

在主机拥有多个IP地址时,返回能够连通对端网络的自身主机IP

func GetRequestIP

func GetRequestIP(r *http.Request) string

返回HTTP请求IP,优先级(X-Real-IP>X-Forwarded-For>Proxy-Client-IP>WL-Proxy-Client-IP")

func GetUploadFileSize

func GetUploadFileSize(upfile multipart.File) (int64, error)

返回HTTP upload文件的大小

func HttpTransportWithCache

func HttpTransportWithCache(maxIdle, cacheTo time.Duration)

func Inet_aton

func Inet_aton(ipnr net.IP) int64

将IP转换为整数值

func Inet_ntoa

func Inet_ntoa(ipnr int64) net.IP

将整数IP转换为Go

func IsPrivateIP

func IsPrivateIP(ip stdnet.IP) bool

func IsPublicIP

func IsPublicIP(IP net.IP) bool

返回是否是公网IP

func NetHexToIPv4

func NetHexToIPv4(s string) net.IP

func NewResolver

func NewResolver(list []string) *stdnet.Resolver

func OverrideDefaultResolver

func OverrideDefaultResolver(list []string)

func UpdateResolveList

func UpdateResolveList(list []string)

Types

type NSCache

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

func NewNsCache

func NewNsCache(refreshRate time.Duration) *NSCache

func (*NSCache) Fetch

func (r *NSCache) Fetch(address string) ([]net.IP, error)

func (*NSCache) FetchOne

func (r *NSCache) FetchOne(address string) (net.IP, error)

func (*NSCache) FetchOneString

func (r *NSCache) FetchOneString(address string) (string, error)

func (*NSCache) Lookup

func (r *NSCache) Lookup(address string) ([]net.IP, error)

func (*NSCache) Refresh

func (r *NSCache) Refresh()

type NSServer

type NSServer []string

func GetRhNsByNic

func GetRhNsByNic(name string) (NSServer, error)

type NSServers

type NSServers struct {
	NSServer
	NicNS map[string]NSServer `json:"nicns" yaml:"nicns"` //ns set by nic
}

func GetLocalNS

func GetLocalNS() (NSServers, error)

type Resolver

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

type RouteItem

type RouteItem struct {
	Iface   string
	Dst     net.IP
	Gateway net.IP

	Flags  uint32
	RefCnt int
	Use    int
	Metric int
	Mask   net.IPMask
	MTU    int
	Window int
	IRTT   int
}

func ListGateway

func ListGateway() ([]*RouteItem, error)

type Size

type Size interface {
	Size() int64
}

获取文件大小的接口

type Stat

type Stat interface {
	Stat() (os.FileInfo, error)
}

获取文件信息的接口

Jump to

Keyboard shortcuts

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