myip

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Detectors = []Detector{

	&STUNDetector{Host: "stun:stun.l.google.com:19302"},
	&STUNDetector{Host: "stun:stun1.l.google.com:19302"},
	&STUNDetector{Host: "stun:stun2.l.google.com:19302"},
	&STUNDetector{Host: "stun:stun3.l.google.com:19302"},
	&STUNDetector{Host: "stun:stun4.l.google.com:19302"},
	&STUNDetector{Host: "stun:stun.aa.net.uk:3478"},
	&STUNDetector{Host: "stun:stun.hoiio.com:3478"},
	&STUNDetector{Host: "stun:stun.acrobits.cz:3478"},
	&STUNDetector{Host: "stun:stun.voip.blackberry.com:3478"},
	&STUNDetector{Host: "stun:stun.sip.us:3478"},
	&STUNDetector{Host: "stun:stun.antisip.com:3478"},
	&STUNDetector{Host: "stun:stun.avigora.fr:3478"},
	&STUNDetector{Host: "stun:stun.linphone.org:3478"},
	&STUNDetector{Host: "stun:stun.voipgate.com:3478"},
	&STUNDetector{Host: "stun:stun.cope.es:3478"},
	&STUNDetector{Host: "stun:stun.bluesip.net:3478"},
	&STUNDetector{Host: "stun:stun.solcon.nl:3478"},
	&STUNDetector{Host: "stun:stun.uls.co.za:3478"},

	&HTTPDetector{Host: "http://inet-ip.info/ip"},
	&HTTPDetector{Host: "http://whatismyip.akamai.com/"},
	&HTTPDetector{Host: "https://ipecho.net/plain"},
	&HTTPDetector{Host: "https://eth0.me/"},
	&HTTPDetector{Host: "https://ifconfig.me/ip"},
	&HTTPDetector{Host: "https://checkip.amazonaws.com/"},
	&HTTPDetector{Host: "https://wgetip.com/"},
	&HTTPDetector{Host: "https://ip.tyk.nu/"},
	&HTTPDetector{Host: "https://l2.io/ip"},
	&HTTPDetector{Host: "https://api.ipify.org/"},
	&HTTPDetector{Host: "https://myexternalip.com/raw"},
	&HTTPDetector{Host: "https://icanhazip.com"},
	&HTTPDetector{Host: "https://ifconfig.io/ip"},
	&HTTPDetector{Host: "https://ifconfig.co/ip"},
	&HTTPDetector{Host: "https://ipinfo.io/ip"},
	&HTTPDetector{Host: "https://wtfismyip.com/text"},

	&DNSDetector{Domain: "myip.opendns.com.", Server: "resolver1.opendns.com:53", QueryType: "A"},
	&DNSDetector{Domain: "myip.opendns.com.", Server: "resolver2.opendns.com:53", QueryType: "A"},
	&DNSDetector{Domain: "myip.opendns.com.", Server: "resolver3.opendns.com:53", QueryType: "A"},
	&DNSDetector{Domain: "myip.opendns.com.", Server: "resolver4.opendns.com:53", QueryType: "A"},
	&DNSDetector{Domain: "whoami.akamai.net.", Server: "ns1-1.akamaitech.net:53", QueryType: "A"},
	&DNSDetector{Domain: "whoami.ultradns.net.", Server: "pdns1.ultradns.net:53", QueryType: "A"},
	&DNSDetector{Domain: "o-o.myaddr.l.google.com.", Server: "ns1.google.com:53", QueryType: "TXT"},
}

Functions

func GetPublicIP

func GetPublicIP(localAddr string, count int, timeoutS int) (net.IP, error)

GetPublicIP concurrently discovers the public IP using multiple detectors. It waits until at least 'count' detectors return the same IP, and then returns this IP.

Types

type DNSDetector

type DNSDetector struct {
	Domain    string
	Server    string
	QueryType string
}

DNSDetector is a struct for configuring DNS queries. It contains the domain to query, the DNS server to use, and the type of DNS query.

func (*DNSDetector) Discover

func (d *DNSDetector) Discover(ctx context.Context, localAddr string) (net.IP, error)

Discover performs a DNS query based on the DNSDetector configuration and returns the discovered IP. It supports A and TXT record queries.

type Detector

type Detector interface {
	Discover(ctx context.Context, localAddr string) (ip net.IP, err error)
}

type HTTPDetector

type HTTPDetector struct {
	Host string
}

HTTPDetector is a struct for configuring HTTP queries. It contains the host to query for IP discovery.

func (*HTTPDetector) Discover

func (d *HTTPDetector) Discover(ctx context.Context, localAddr string) (net.IP, error)

Discover performs an HTTP query based on the HTTPDetector configuration and returns the discovered IP.

type STUNDetector

type STUNDetector struct {
	Host string
}

STUNDetector is used to discover IP address via STUN protocol. It contains the host of the STUN server.

func (*STUNDetector) Discover

func (d *STUNDetector) Discover(ctx context.Context, localAddr string) (net.IP, error)

Discover performs a STUN query to the configured host and returns the discovered IP.

Jump to

Keyboard shortcuts

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