Documentation ¶
Index ¶
- Constants
- Variables
- func CIDRListAll(cidr string) ([]string, error)
- func CIDRToMask(cidr string) (net.IPMask, error)
- func CidrContainsIP(cidr, ip string) (bool, error)
- func DecodeURL(encodedUrl string) (string, error)
- func Dial(network, address string) (net.Conn, error)
- func DiscoverGateway() (net.IP, error)
- func GetAllLANIPv4CIDRs() ([]string, error)
- func GetAllNicNames() ([]string, error)
- func GetOutboundIP() (net.IP, error)
- func GetPrivateIPs() ([]net.IP, error)
- func GetPublicIPOL(proxy string) (net.IP, error)
- func GetRandomAvailablePort(nettype string) (int, error)
- func IsAndOnlyDomain(str string) bool
- func IsAudioUrl(url string) bool
- func IsDomain(domain string) bool
- func IsDomainONLINE(domain string) bool
- func IsFilePath(s string) bool
- func IsIPString(s string) bool
- func IsImageUrl(url string) bool
- func IsLocalInboundPortClear(nettype string, port int) (bool, error)
- func IsLocalPortUsing(nettype string, port int) (bool, error)
- func IsPrivilegedPort(port int) bool
- func IsRegistrable(domain string) bool
- func IsRemotePortOpen(nettype string, port int) (bool, error)
- func IsUrl(s string) bool
- func IsValidPort(port int) bool
- func IsVideoUrl(url string) bool
- func Join(baseUrl string, relUrl string) (absUrl string, err error)
- func LastPath(urlstr string) string
- func ListenAny(network, addr string) (net.Listener, error)
- func ListenCop(network, addr string) (net.Listener, error)
- func LookupIP(host string) ([]net.IP, error)
- func MaskToInt(mask net.IPMask) (uint16, error)
- func ParseAddr(addr net.Addr) (IP net.IP, port int, err error)
- func ParseHostAddrOnline(addr string) (IP net.IP, port int, err error)
- func ParseProxyAddr(address string) (proxyType, host string, err error)
- func RemoveDuplicateUrl(urls []string) []string
- type AddrParser
- type AddrSlice
- type Auth
- type CidrRanger
- type CodecConn
- func (c *CodecConn) Close() error
- func (c *CodecConn) LocalAddr() net.Addr
- func (c *CodecConn) Read(p []byte) (n int, err error)
- func (c *CodecConn) RemoteAddr() net.Addr
- func (c *CodecConn) SetDeadline(t time.Time) error
- func (c *CodecConn) SetReadDeadline(t time.Time) error
- func (c *CodecConn) SetWriteDeadline(t time.Time) error
- func (c *CodecConn) Write(p []byte) (n int, err error)
- type DNSClient
- func (dl *DNSClient) AddCustomDNSServer(host string) error
- func (dl *DNSClient) CleanCustomServers() *DNSClient
- func (dl *DNSClient) LookupAddr(addr string) (names []string, err error)
- func (dl *DNSClient) LookupIP(host string) ([]net.IP, error)
- func (dl *DNSClient) RemoveCustomDNSServer(host, ip string)
- func (dl *DNSClient) UseSysDNSIfNoCustom(use bool) *DNSClient
- type DNSResolver
- type DialFunc
- type DialWithCtxFunc
- type Dialer
- type DialerWithCtx
- type Domain
- type GeoFinder
- type Host
- type IP
- type IPNet
- type Interface
- type IpGeo
- type Listener
- type LookupIPWithCtxFunc
- type MultiListener
- type NicAddr
- type NicInfo
- type Path
- type PopConn
- func (c *PopConn) Close() error
- func (c *PopConn) LocalAddr() net.Addr
- func (c *PopConn) Read(b []byte) (int, error)
- func (c *PopConn) RemoteAddr() net.Addr
- func (c *PopConn) SetDeadline(t time.Time) error
- func (c *PopConn) SetReadDeadline(t time.Time) error
- func (c *PopConn) SetWriteDeadline(t time.Time) error
- func (c *PopConn) Write(b []byte) (n int, err error)
- type PopListener
- type Scheme
- type Url
- func (u *Url) SetHost(host string) *Url
- func (u *Url) SetPass(pass string) *Url
- func (u *Url) SetPath(paths []string) *Url
- func (u *Url) SetPort(port int) *Url
- func (u *Url) SetProto(proto string) *Url
- func (u *Url) SetQueries(queries map[string]string) *Url
- func (u *Url) SetUser(user string) *Url
- func (u *Url) String() string
- type UrlAuth
- type UrlHost
- type Whois
Constants ¶
const ( /* public schemes */ SchemeUnknown = iota SchemeHttp SchemeHttps SchemeFtp SchemeFtps SchemeMailto SchemeFile SchemeIdap SchemeNews SchemeGopher SchemeTelnet SchemeWais SchemeNntp SchemeData SchemeIrc SchemeIrcs SchemeWorldwind SchemeMms SchemeSocks4 SchemeSocks4a SchemeSocks5 SchemeSocks5s SchemeSocksHttp SchemeSocksHttps SchemeShadowsocks /* custom schemes */ SchemeSvn SchemeHg SchemeGit SchemeThunder SchemeTencent SchemeEd2k SchemeMagnet SchemeTwitter )
Variables ¶
var ( // SysDNSResolver uses the system DNS to resolve host names SysDNSResolver = NewDNSClient().CleanCustomServers().UseSysDNSIfNoCustom(true) )
Functions ¶
func CIDRListAll ¶
List all ip address contained in this cidr
func CIDRToMask ¶
Extracts IP mask from CIDR address.
func CidrContainsIP ¶
func DecodeURL ¶
https://video-icn1-1.xx.fbcdn.net/v/t42.9040-2/58467180_2666273813399564_6679224605468524544_n.mp4?_nc_cat=100\u0026efg=eyJybHIiOjY5NCwicmxhIjo1MTIsInZlbmNvZGVfdGFnIjoic3ZlX3NkIn0=\u0026rl=694\u0026vabr=386\u0026_nc_ht=video-icn1-1.xx\u0026oh=881ead117c700970945a89716b3a0b54\u0026oe=5CB9BAA5
func DiscoverGateway ¶
func GetAllLANIPv4CIDRs ¶
func GetAllNicNames ¶
func GetOutboundIP ¶
get preferred outbound ip of this machine it will fail if device is not connected to LAN router
func GetPublicIPOL ¶
get my wan IPs by 3rd party service
func GetRandomAvailablePort ¶
func IsAndOnlyDomain ¶
"http://bing.com/" is domain url, "http://bing.com/search" is not domain url
func IsAudioUrl ¶
func IsDomainONLINE ¶
func IsFilePath ¶
func IsIPString ¶
func IsImageUrl ¶
func IsLocalInboundPortClear ¶
端口是否通畅 如果发起检测端不是你的程序,需要开关端口监听多次才能确定,因为,如果端口可访问,也可能是被映射到别的电脑上而那个电脑的该端口也被监听了
func IsRegistrable ¶
Principle: WHOIS information of domains which are not taken include "No match".
func IsRemotePortOpen ¶
只能检测端口是否正开启,如果未开启,可能是多种原因,比如主机关机、防火墙、端口未映射、端口没有服务在监听等
func IsValidPort ¶
func IsVideoUrl ¶
func Join ¶
Combine absolute path and relative path to get a new absolute path If relUrl is absolute url, returns this relUrl
func ParseHostAddrOnline ¶
"HOSTNAME" / "DOMAIN" / "IP" / ":PORT" / "HOSTNAME:PORT" / "DOMAIN:PORT" / "IP:PORT" -> net.IP, port return port maybe -1, this is NOT an error NOTICE: ResolveIPAddr() & LookupIP() API can't recognize "1127.0.0.1" or "abc127.0.0.1" style illegal IP string, they still returns a IP address and nil error
func ParseProxyAddr ¶
func RemoveDuplicateUrl ¶
Types ¶
type AddrParser ¶
type AddrParser struct {
// contains filtered or unexported fields
}
func NewParser ¶
func NewParser(address_string string) *AddrParser
func (*AddrParser) Scheme ¶
func (ap *AddrParser) Scheme() string
func (*AddrParser) Split ¶
func (ap *AddrParser) Split() (*AddrSlice, error)
func (*AddrParser) Verify ¶
func (ap *AddrParser) Verify() error
type AddrSlice ¶
type AddrSlice struct { Scheme string // like "http", "ftp" Domain Domain // like "google.com" Auth UrlAuth // like "usr:pwd" Host UrlHost // like "google.com:443" Path Path // like "?article=1260&lang=en#comment" }
func ParseUrl ¶
NOTICE url.Parse("192.168.1.1:80") reports error because RFC3986 says "192.168.1.1:80" is an invalid url, the correct way is "//192.168.1.1:80". In gaddr library and urlx library, "192.168.1.1:80" is a valid url because it is used a lot Reference: https://github.com/golang/go/issues/19297
type CidrRanger ¶
type CidrRanger struct {
// contains filtered or unexported fields
}
CidrRanger is a fast IP to CIDR lookup.
func NewCidrRanger ¶
func NewCidrRanger() *CidrRanger
type CodecConn ¶
type CodecConn struct {
// contains filtered or unexported fields
}
CodecConn is a generic stream-oriented network connection that can be compressed and decompressed. It implements net.Conn interface. It is used to compress/decompress network connection stream, for example, when transferring log files or JSON files over the Internet, adding a compression algorithm like snappy can greatly improve the efficiency of data transfer.
func NewCodecConn ¶
func NewCodecConn(conn net.Conn, codec io.ReadWriteCloser) *CodecConn
NewCodecConn create CodecConn with original connection and codec io.ReadWriteCloser. Note: you should implement data compress/decompress at `codecReadWriteCloser`
func (*CodecConn) RemoteAddr ¶
RemoteAddr implements net.Conn.
func (*CodecConn) SetDeadline ¶
SetDeadline implements net.Conn.
func (*CodecConn) SetReadDeadline ¶
SetReadDeadline implements net.Conn.
func (*CodecConn) SetWriteDeadline ¶
SetWriteDeadline implements net.Conn.
type DNSClient ¶
func NewDNSClient ¶
func NewDNSClient() *DNSClient
func (*DNSClient) AddCustomDNSServer ¶
AddCustomDNSServer adds new custom DNS server. host samples: Plain: 8.8.8.8:53 Plain: 8.8.4.4:53 Plain: 1.0.0.1:53 Plain: 1.1.1.1:53 DNS-over-TLS: tls://dns.adguard.com DNS-over-HTTPS: https://8.8.8.8/dns-query DNS-over-HTTPS: https://dns.adguard.com/dns-query DNSCrypt-stamp: sdns://AQIAAAAAAAAAFDE3Ni4xMDMuMTMwLjEzMDo1NDQzINErR_JS3PLCu_iZEIbq95zkSV2LFsigxDIuUso_OQhzIjIuZG5zY3J5cHQuZGVmYXVsdC5uczEuYWRndWFyZC5jb20 DNS-over-QUIC: quic://dns.adguard.com
More public DNS servers: https://github.com/DNSCrypt/dnscrypt-resolvers/blob/master/v3/public-resolvers.md
func (*DNSClient) CleanCustomServers ¶
CleanCustomServers uses the system DNS to resolve host names.
func (*DNSClient) LookupAddr ¶
LookupAddr looks up host names or domains by ip address from DNS server, if no DNS server is set up locally, then a query request will be sent to the default gateway.
func (*DNSClient) RemoveCustomDNSServer ¶
func (*DNSClient) UseSysDNSIfNoCustom ¶
type DNSResolver ¶
type DNSResolver interface { LookupIP(host string) ([]net.IP, error) LookupAddr(addr string) (names []string, err error) }
DNSResolver is used to implement custom name resolution
type DialWithCtxFunc ¶
type DialerWithCtx ¶
type Domain ¶
type Domain struct { TLD string // "com" | "com.cn" SLD_ROOT string // "baidu" TRD_SUB string // "www" SiteDomain string // "baidu.com" }
func ParseDomain ¶
NOTICE This an offline domain parse function, please update source repo often
func ParseONLINE ¶
NOTICE 优点: 从权威网站下载TLD列表,判断结果准确 缺点: 初始化或者更新时必须在线工作,下载期间接口响应慢
type GeoFinder ¶
type GeoFinder struct {
// contains filtered or unexported fields
}
func NewGeoFinderONLINE ¶
type IPNet ¶
IPNet defines IP network, or IP range. Notice: Valid IPNet samples: 192.168.7.0/24 Invalid IPNet samples: 192.168.7.123/24
func WrapIPNetPtr ¶
type Interface ¶
func Interfaces ¶
func WrapIfiPtr ¶
func (*Interface) IsBroadcast ¶
func (*Interface) IsLoopBack ¶
func (*Interface) IsMulticast ¶
func (*Interface) IsPointToPoint ¶
type LookupIPWithCtxFunc ¶
type MultiListener ¶
type MultiListener struct {
// contains filtered or unexported fields
}
func NewMultiListener ¶
func NewMultiListener() *MultiListener
NewMultiListener creates new MultiListener.
func (*MultiListener) AddListen ¶
func (ml *MultiListener) AddListen(network, addr string) error
AddListen add new listen address.
func (*MultiListener) Addr ¶
func (ml *MultiListener) Addr() []string
Addr returns all the listener's network address.
func (*MultiListener) Close ¶
func (ml *MultiListener) Close() error
Close closes all the listeners. Any blocked 'Accept' operations will be unblocked and return errors.
func (*MultiListener) CloseOne ¶
func (ml *MultiListener) CloseOne(network, addr string) error
CloseOne closes one listener.
type NicInfo ¶
type NicInfo struct { Name string Desc string MAC string Addrs []NicAddr IsPhysical bool // Is physical network card or virtual network card Flags string MTU int }
func GetNicInfo ¶
type PopConn ¶
PopConn is packet-oriented protocols connection. It implements net.Conn, makes PacketConn used like a net.Conn.
func (*PopConn) RemoteAddr ¶
type PopListener ¶
type PopListener struct {
// contains filtered or unexported fields
}
PopListener is packet-oriented protocols listener. It implements net.Listener, makes PacketConn used like a net.Listener.
func ListenPop ¶
func ListenPop(network, addr string) (*PopListener, error)
func (*PopListener) Addr ¶
func (l *PopListener) Addr() net.Addr
func (*PopListener) Close ¶
func (l *PopListener) Close() error
type Url ¶
type UrlHost ¶
type UrlHost struct { Domain string // like "163.com" IP string // like "8.8.8.8" Port int // like "443" }
type Whois ¶
type Whois struct { // Query and Host are copied from the Request. // Query string Host string // FetchedAt is the date and time the response was fetched from the server. FetchedAt time.Time // Body contains the raw bytes of the network response (minus HTTP headers). //Body []byte Body string }
Cloned from github.com/domainr/whois Whois response represents a whois response from a server.