protocol

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package protocol implements all the generic protocols to detect public IP addresses. Generic protocols are not tied to a particular server (e.g., Cloudflare).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Constant added in v1.9.3

type Constant string

func (Constant) Switch added in v1.9.3

func (c Constant) Switch(_ bool) string

type DNSOverHTTPS

type DNSOverHTTPS struct {
	ProviderName     string // name of the protocol
	Is1111UsedForIP4 bool   // whether 1.1.1.1 is used
	Param            map[ipnet.Type]struct {
		URL   Switch           // the DoH server
		Name  string           // domain name to query
		Class dnsmessage.Class // DNS class to query
	}
}

DNSOverHTTPS represents a generic detection protocol using DNS over HTTPS.

func (*DNSOverHTTPS) GetIP

func (p *DNSOverHTTPS) GetIP(ctx context.Context, ppfmt pp.PP, ipNet ipnet.Type, use1001 bool) (netip.Addr, bool)

GetIP detects the IP address by DNS over HTTPS.

func (*DNSOverHTTPS) Name

func (p *DNSOverHTTPS) Name() string

Name of the detection protocol.

func (*DNSOverHTTPS) ShouldWeCheck1111 added in v1.9.3

func (p *DNSOverHTTPS) ShouldWeCheck1111() bool

ShouldWeCheck1111 returns whether we should check 1.1.1.1.

type Field

type Field struct {
	ProviderName     string // name of the detection protocol
	Is1111UsedforIP4 bool
	Param            map[ipnet.Type]struct {
		URL   Switch // URL of the detection page
		Field string // name of the field holding the IP address
	}
}

Field represents a generic detection protocol to parse an HTTP response.

func (*Field) GetIP

func (p *Field) GetIP(ctx context.Context, ppfmt pp.PP, ipNet ipnet.Type, use1001 bool) (netip.Addr, bool)

GetIP detects the IP address by parsing the HTTP response.

func (*Field) Name

func (p *Field) Name() string

Name of the detection protocol.

func (*Field) ShouldWeCheck1111 added in v1.9.3

func (p *Field) ShouldWeCheck1111() bool

ShouldWeCheck1111 returns whether we should check 1.1.1.1.

type HTTP

type HTTP struct {
	ProviderName     string                // name of the protocol
	Is1111UsedForIP4 bool                  // whether 1.1.1.1 is used
	URL              map[ipnet.Type]Switch // URL of the detection page
}

HTTP represents a generic detection protocol to use an HTTP response directly.

func (*HTTP) GetIP

func (p *HTTP) GetIP(ctx context.Context, ppfmt pp.PP, ipNet ipnet.Type, use1001 bool) (netip.Addr, bool)

GetIP detects the IP address by using the HTTP response directly.

func (*HTTP) Name

func (p *HTTP) Name() string

Name of the detection protocol.

func (*HTTP) ShouldWeCheck1111 added in v1.9.3

func (p *HTTP) ShouldWeCheck1111() bool

ShouldWeCheck1111 returns whether we should check 1.1.1.1.

type Local

type Local struct {
	// Name of the detection protocol.
	ProviderName string

	// Whether 1.1.1.1 is used for IPv4
	Is1111UsedForIP4 bool

	// The target IP address of the UDP packet to be sent.
	RemoteUDPAddr map[ipnet.Type]Switch
}

Local detects the IP address by pretending to send out an UDP packet and using the source IP address assigned by the system. In most cases it will detect the IP address of the network interface toward the internet. (No actual UDP packets will be sent out.)

func (*Local) GetIP

func (p *Local) GetIP(_ctx context.Context, ppfmt pp.PP, ipNet ipnet.Type, use1001 bool) (netip.Addr, bool)

GetIP detects the IP address by pretending to send an UDP packet. (No actual UDP packets will be sent out.)

func (*Local) Name

func (p *Local) Name() string

Name of the detection protocol.

func (*Local) ShouldWeCheck1111 added in v1.9.3

func (p *Local) ShouldWeCheck1111() bool

ShouldWeCheck1111 returns whether we should check 1.1.1.1.

type Switch added in v1.9.3

type Switch interface {
	Switch(use1001 bool) string
}

type Switchable added in v1.9.3

type Switchable struct {
	ValueFor1001 string
	ValueFor1111 string
}

func (Switchable) Switch added in v1.9.3

func (s Switchable) Switch(use1001 bool) string

Jump to

Keyboard shortcuts

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