fsdns

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: May 7, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultHostsFile fsresolver.LookupIPer = NewHostsFile("")

DefaultHostsFile os default hosts file

View Source
var DefaultResolvConf = NewResolvConf("")

DefaultResolvConf os default ResolvConf

Functions

func LookupIPByNS

func LookupIPByNS(ctx context.Context, network, host string, ns net.Addr) ([]net.IP, error)

LookupIPByNS LookupIP with nameserver

func LookupIPFromHosts added in v0.0.5

func LookupIPFromHosts(ctx context.Context, network, host string) ([]net.IP, error)

LookupIPFromHosts find domain in hosts file

func ParseHosts

func ParseHosts(content []byte) map[string][]net.IP

ParseHosts hosts content

func ParserServers

func ParserServers(lines []string) []net.Addr

ParserServers parser servers addr from lines

func ResolvNameserver

func ResolvNameserver() []string

ResolvNameserver get nameserver list from DefaultResolvConf

func ServersFromEnv

func ServersFromEnv() []net.Addr

ServersFromEnv parser nameserver list from os.env 'FSNET_NAMESERVER'

eg: export FSNET_NAMESERVER=1.1.1.1,8.8.8.8:53

Types

type Client

type Client struct {
	HostsFile fsresolver.LookupIPer

	// LookupIPFilter after query dns success, filter the result
	LookupIPFilter func(ctx context.Context, network, host string, ns net.Addr, result []net.IP) ([]net.IP, error)

	// Servers nameserver list,eg 114.114.114.114:53
	Servers []net.Addr
	// contains filtered or unexported fields
}

Client prue dns client

func (*Client) GetServers

func (client *Client) GetServers() []net.Addr

GetServers get servers

func (*Client) LookupIP

func (client *Client) LookupIP(ctx context.Context, network, host string) ([]net.IP, error)

LookupIP lookup ip

func (*Client) LookupIPAddr

func (client *Client) LookupIPAddr(ctx context.Context, host string) ([]net.IPAddr, error)

LookupIPAddr lookup ipaddr

func (*Client) ResolverInterceptor

func (client *Client) ResolverInterceptor() *fsresolver.Interceptor

ResolverInterceptor to ResolverInterceptor

func (*Client) SetServers

func (client *Client) SetServers(servers []net.Addr)

SetServers set servers

type HostsFile

type HostsFile struct {
	fsfs.WatchFile
	// contains filtered or unexported fields
}

HostsFile hosts file parser

func NewHostsFile

func NewHostsFile(hostsPath string) *HostsFile

NewHostsFile create new HostsFile instance

if start fail,then panic
already start watch the hostPath
when hostPath is empty, use the default path:
on unix like system,the default path is /etc/hosts.
the default hostsPath can set by Environment Variables 'FSGO_HOSTS',
eg: export FSGO_HOSTS=./my_hosts

func (*HostsFile) LookupIP

func (hf *HostsFile) LookupIP(_ context.Context, network, host string) ([]net.IP, error)

LookupIP lookup ip from hosts file

type ResolvConf

type ResolvConf struct {
	fsfs.WatchFile
	// contains filtered or unexported fields
}

ResolvConf parser for resolv.conf

func NewResolvConf

func NewResolvConf(confPath string) *ResolvConf

NewResolvConf create new ResolvConf instance

already start watch the confPath

func (*ResolvConf) Config

func (rf *ResolvConf) Config() *ResolverConfig

Config 读取 ResolverConfig

func (*ResolvConf) Nameserver

func (rf *ResolvConf) Nameserver() []string

Nameserver get nameserver list from file

type ResolverConfig

type ResolverConfig struct {
	Nameserver []string
	Search     []string
	SortList   []string
	Options    []string
}

ResolverConfig resolv.conf see https://man7.org/linux/man-pages/man5/resolv.conf.5.html

func ParseResolv

func ParseResolv(content []byte) *ResolverConfig

ParseResolv parse resolv.conf content

Jump to

Keyboard shortcuts

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