gaddr

package
v0.0.0-...-f3abbe6 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2020 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
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

This section is empty.

Functions

func CIDRListAll

func CIDRListAll(cidr string) ([]string, error)

List all ip address contained in this cidr

func CIDRtotMask

func CIDRtotMask(cidr string) (net.IPMask, error)

Extracts IP mask from CIDR address.

func CidrContainsIP

func CidrContainsIP(cidr, ip string) (bool, error)

func DecodeURL

func DecodeURL(encodedUrl string) (string, error)

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 GetAllLANIPv4CIDRs

func GetAllLANIPv4CIDRs() ([]string, error)

func GetAllNicNames

func GetAllNicNames() ([]string, error)

func GetLanIps

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

get all my local IPs

func GetOutboundIP

func GetOutboundIP() (net.IP, error)

get preferred outbound ip of this machine it will fail if device is not connected to LAN router

func GetRandomAvailablePort

func GetRandomAvailablePort(nettype string) (int, error)

func GetWanIpOL

func GetWanIpOL(proxy string) (net.IP, error)

get my wan IPs by 3rd party service

func IsAndOnlyDomain

func IsAndOnlyDomain(str string) bool

"http://bing.com/" is domain url, "http://bing.com/search" is not domain url

func IsAudioUrl

func IsAudioUrl(url string) bool

func IsDomain

func IsDomain(domain string) bool

func IsDomainONLINE

func IsDomainONLINE(domain string) bool

func IsFilePath

func IsFilePath(s string) bool

func IsIPString

func IsIPString(s string) bool

func IsImageUrl

func IsImageUrl(url string) bool

func IsLocalInboundPortClear

func IsLocalInboundPortClear(nettype string, port int) (bool, error)

端口是否通畅 如果发起检测端不是你的程序,需要开关端口监听多次才能确定,因为,如果端口可访问,也可能是被映射到别的电脑上而那个电脑的该端口也被监听了

func IsLocalPortUsing

func IsLocalPortUsing(nettype string, port int) (bool, error)

func IsPrivilegedPort

func IsPrivilegedPort(port int) bool

Privileged port needs root

func IsRegistrable

func IsRegistrable(domain string) bool

Principle: WHOIS information of domains which are not taken include "No match".

func IsRemotePortOpen

func IsRemotePortOpen(nettype string, port int) (bool, error)

只能检测端口是否正开启,如果未开启,可能是多种原因,比如主机关机、防火墙、端口未映射、端口没有服务在监听等

func IsUrl

func IsUrl(s string) bool

func IsValidPort

func IsValidPort(port int) bool

func IsVideoUrl

func IsVideoUrl(url string) bool

func Join

func Join(baseUrl string, relUrl string) (absUrl string, err error)

Combine absolute path and relative path to get a new absolute path If relUrl is absolute url, returns this relUrl

func LastPath

func LastPath(urlstr string) string

func MaskToInt

func MaskToInt(mask net.IPMask) (uint16, error)

Converts IP mask to 16 bit unsigned integer.

func ParseAddr

func ParseAddr(addr net.Addr) (IP net.IP, port int, err error)

func ParseHostAddrOnline

func ParseHostAddrOnline(addr string) (IP net.IP, port int, err error)

"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 ParseIP

func ParseIP(s string) (net.IP, error)

func ParseProxyAddr

func ParseProxyAddr(address string) (proxyType, host string, err error)

func RemoveDuplicateUrl

func RemoveDuplicateUrl(urls []string) []string

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
	Domain Domain
	Auth   UrlAuth
	Host   UrlHost
	Path   Path
}

func ParseUrl

func ParseUrl(urlStr string) (*AddrSlice, error)

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 xaddr 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

func (*AddrSlice) String

func (us *AddrSlice) String() string

type Domain

type Domain struct {
	TLD        string // "com" | "com.cn"
	SLD_ROOT   string // "baidu"
	TRD_SUB    string // "www"
	SiteDomain string // "baidu.com"
}

func ParseDomain

func ParseDomain(domain string) (*Domain, error)

NOTICE This an offline domain parse function, please update source repo often

func ParseONLINE

func ParseONLINE(domain string) (*Domain, error)

NOTICE 优点: 从权威网站下载TLD列表,判断结果准确 缺点: 初始化或者更新时必须在线工作,下载期间接口响应慢

type GeoFinder

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

func NewGeoFinderONLINE

func NewGeoFinderONLINE() (*GeoFinder, error)

func (*GeoFinder) Close

func (gf *GeoFinder) Close()

func (*GeoFinder) GetByIP

func (gf *GeoFinder) GetByIP(ip net.IP) (*IpGeo, error)

func (*GeoFinder) GetByIPString

func (gf *GeoFinder) GetByIPString(s string) (*IpGeo, error)

type IpGeo

type IpGeo struct {
	Country  string
	Region   string
	Province string
	City     string
	CityId   int64
	ISP      string
}

type IpType

type IpType int
const (
	NotIP         IpType = 0
	IPv4_LAN      IpType = 1
	IPv4_WAN      IpType = 2
	IPv6_LAN      IpType = 3
	IPv6_WAN      IpType = 4
	IPv4_LOOPBACK IpType = 5
	IPv6_LOOPBACK IpType = 6
	IPv4_ANY      IpType = 7
	IPv6_ANY      IpType = 8
)

const for CheckIPString

func CheckIP

func CheckIP(ip net.IP) IpType

func CheckIPString

func CheckIPString(s string) IpType

check is IPv4_LAN or IPv4_WAN or IPv6 or NotIP

type NicAddr

type NicAddr struct {
	IP      net.IP
	Netmask net.IPMask
	CIDR    string
}

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

func GetNicInfo(name string) (NicInfo, error)

type Path

type Path struct {
	Str    string
	Dirs   []string
	Params map[string][]string
}

type Scheme

type Scheme int

type UrlAuth

type UrlAuth struct {
	User        string
	Password    string
	PasswordSet bool
}

func (*UrlAuth) String

func (ua *UrlAuth) String() string

type UrlChunk

type UrlChunk struct {
	Scheme   string
	User     string
	Password string
	Host     string
	Port     int64
	Path     string
	Param    string
}

func ParseUrlString

func ParseUrlString(u string) (*UrlChunk, error)

mongodb://user:password@127.0.0.1:27717 ftp://user:password@127.0.0.1:1999/files/abc.mp4

type UrlHost

type UrlHost struct {
	Domain string
	IP     string
	Port   int
}

func (*UrlHost) String

func (uh *UrlHost) String() string

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.

func GetWhoisWithDomain

func GetWhoisWithDomain(domain string) (*Whois, error)

func GetWhoisWithIP

func GetWhoisWithIP(ip string) (*Whois, error)

Jump to

Keyboard shortcuts

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