ips

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: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// OutputTypeText represents the text output format.
	OutputTypeText = "text"

	// OutputTypeJSON represents the JSON output format.
	OutputTypeJSON = "json"

	// OutputTypeAlfred represents the Alfred output format.
	OutputTypeAlfred = "alfred"

	// DefaultFields represents the default output fields.
	DefaultFields = "country,province,city,isp"
)

Variables

View Source
var DownloadMap = map[string]string{
	"city.free.ipdb":      "https://raw.githubusercontent.com/ipipdotnet/ipdb-go/master/city.free.ipdb",
	"qqwry.dat":           "https://github.com/metowolf/qqwry.dat/releases/download/20231025/qqwry.dat",
	"zxipv6wry.db":        "https://raw.githubusercontent.com/ZX-Inc/zxipdb-python/main/data/ipv6wry.db",
	"GeoLite2-City.mmdb":  "https://git.io/GeoLite2-City.mmdb",
	"ip2region.xdb":       "https://raw.githubusercontent.com/lionsoul2014/ip2region/master/data/ip2region.xdb",
	"dbip-city-lite.mmdb": "https://download.db-ip.com/free/dbip-city-lite-2023-11.mmdb.gz",
	"dbip-asn-lite.mmdb":  "https://download.db-ip.com/free/dbip-asn-lite-2023-11.mmdb.gz",
}
View Source
var EFS embed.FS

EFS holds embedded file system data for static assets.

Functions

This section is empty.

Types

type Config

type Config struct {

	// Common
	// IPSDir specifies the working directory for IPS.
	IPSDir string `mapstructure:"-"`

	// Lang specifies the language for the output.
	Lang string `mapstructure:"lang"`

	// Find
	// IPv4File specifies the file is IPv4 database.
	IPv4File []string `mapstructure:"ipv4_file" default:"[\"qqwry.dat\"]"`

	// IPv4Format specifies the format for IPv4 database.
	IPv4Format []string `mapstructure:"ipv4_format"`

	// IPv6File specifies the file is IPv6 database.
	IPv6File []string `mapstructure:"ipv6_file" default:"[\"zxipv6wry.db\"]"`

	// IPv6Format specifies the format for IPv6 database.
	IPv6Format []string `mapstructure:"ipv6_format"`

	// HybridMode specifies the operational mode of the HybridReader.
	// It determines how the HybridReader processes and combines data from multiple IP database readers.
	// Accepted values are "comparison" and "aggregation":
	// - "comparison": Used for comparing data across different databases, where the output includes data from all readers.
	// - "aggregation": Used for creating a unified view of data by aggregating and supplementing missing fields from multiple databases. (default)
	HybridMode string `mapstructure:"hybrid_mode"`

	// Fields lists the output fields.
	// default is country, province, city, isp
	Fields string `mapstructure:"fields" default:"country,province,city,isp"`

	// UseDBFields indicates whether to use database fields. (default is common fields)
	UseDBFields bool `mapstructure:"use_db_fields"`

	// RewriteFiles lists the files for data rewriting.
	RewriteFiles string `mapstructure:"rewrite_files"`

	// OutputType specifies the type of the output. (default is text)
	OutputType string `mapstructure:"output_type"`

	// TextFormat specifies the format for text output.
	// It supports %origin and %values parameters.
	TextFormat string `mapstructure:"text_format" default:"%origin [%values] "`

	// TextValuesSep specifies the separator for values in text output. (default is space)
	TextValuesSep string `mapstructure:"text_values_sep" default:" "`

	// JsonIndent indicates whether the JSON output should be indented.
	JsonIndent bool `mapstructure:"json_indent"`

	// Dump & Pack
	// DPFields lists the output fields for dump and pack operations.
	// default is empty, means all fields
	DPFields string `mapstructure:"dp_fields"`

	// DPRewriterFiles lists the files for rewriting during dump and pack operations.
	DPRewriterFiles string `mapstructure:"dp_rewriter_files"`

	// Database
	// ReaderOption specifies the options for the reader.
	ReaderOption string `mapstructure:"reader_option"`

	// WriterOption specifies the options for the writer.
	WriterOption string `mapstructure:"writer_option"`

	// ReaderJobs specifies the number of concurrent jobs for the reader.
	// It controls how many reading operations can be performed in parallel.
	ReaderJobs int `mapstructure:"reader_jobs"`

	// MyIP
	// LocalAddr specifies the local address (in IP format) that should be used for outbound connections.
	// Useful in systems with multiple network interfaces.
	LocalAddr string `mapstructure:"local_addr"`

	// MyIPCount defines the minimum number of detectors that should return the same IP
	// for the IP to be considered as the system's public IP.
	MyIPCount int `mapstructure:"myip_count" default:"3"`

	// MyIPTimeoutS specifies the maximum duration (in seconds) to wait for the detectors to return an IP.
	MyIPTimeoutS int `mapstructure:"myip_timeout_s"`

	// DNSClientNet specifies the network protocol to be used by the DNS client. tcp, udp, tcp-tls.
	DNSClientNet string `mapstructure:"dns_client_net" default:"udp"`

	// DNSClientTimeoutMs defines the timeout in milliseconds for DNS client requests.
	DNSClientTimeoutMs int `mapstructure:"dns_client_timeout_ms" default:"2000"`

	// DNSClientSingleInflight indicates whether the DNS client should avoid making duplicate
	// queries concurrently.
	DNSClientSingleInflight bool `mapstructure:"dns_client_single_inflight"`

	// MDNSTimeoutS specifies the timeout in seconds for MDNS operations.
	MDNSTimeoutS int `mapstructure:"mdns_timeout_s" default:"10"`

	// MDNSExchangeAddress defines the address of the DNS server to be used for MDNS queries.
	MDNSExchangeAddress string `mapstructure:"mdns_exchange_address" default:"119.29.29.29"`

	// MDNSRetryTimes sets the number of times an MDNS query should be retried on failure.
	MDNSRetryTimes int `mapstructure:"mdns_retry_times" default:"3"`

	// Service
	// Addr specifies the address for the service.
	Addr string `mapstructure:"addr" default:":6860"`
}

Config represents the application's configuration.

func (*Config) ShowConfig

func (c *Config) ShowConfig(allKeys bool) string

type MDNS added in v0.3.2

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

MDNS represents a structure to hold MDNS client and configuration.

func NewMDNS added in v0.3.2

func NewMDNS(conf *Config) (*MDNS, error)

NewMDNS creates a new MDNS instance with the provided configuration.

func (*MDNS) Resolve added in v0.3.2

func (m *MDNS) Resolve(domain string) (*MdnsResponse, error)

Resolve performs the domain name resolution using the MDNS setup.

type Manager

type Manager struct {
	// Conf holds the common configurations.
	Conf *Config
	// contains filtered or unexported fields
}

Manager is a command-line tool for IP operations.

func NewManager

func NewManager(conf *Config) *Manager

NewManager initializes and returns a new Manager instance.

func (*Manager) Download

func (m *Manager) Download(file, _url string) error

Download downloads the database file to ips dir.

func (*Manager) GetIP added in v0.2.5

func (m *Manager) GetIP(c *gin.Context)

GetIP handles the GET /v1/ip endpoint. It takes an IP as a query parameter and returns its associated information in JSON format. Example: GET /v1/ip?ip=<ip> Response: {}

func (*Manager) GetQuery added in v0.2.5

func (m *Manager) GetQuery(c *gin.Context)

GetQuery handles the GET /v1/query endpoint. It takes a text string as a query parameter, parses it into segments, and returns the information associated with each segment. Example: GET /v1/query?text=<text> Response: {"items": [{},{}]}

func (*Manager) InitRouter added in v0.2.5

func (m *Manager) InitRouter()

InitRouter sets up routes and static file servers for the web service. It defines endpoints for API as well as serving static content.

func (*Manager) MDNSFormatTable added in v0.3.2

func (m *Manager) MDNSFormatTable(ret *MdnsResponse) string

MDNSFormatTable formats the MDNS response into a readable table string.

func (*Manager) MDNSResolve added in v0.3.2

func (m *Manager) MDNSResolve(domain string) (string, error)

MDNSResolve resolves the given domain name using MDNS and formats the results in a table.

func (*Manager) MyIP added in v0.2.6

func (m *Manager) MyIP() (string, error)

func (*Manager) NoRoute added in v0.2.5

func (m *Manager) NoRoute(c *gin.Context)

NoRoute handles 404 Not Found errors. If the request URL starts with "/api" or "/static", it responds with a JSON error. Otherwise, it redirects to the root path.

func (*Manager) Pack

func (m *Manager) Pack(_format, file []string, _outputFormat, outputFile string) error

Pack reads data from a database file, processes it, and writes it to an output.

func (*Manager) ParseText

func (m *Manager) ParseText(text string) (string, error)

ParseText takes a text input, parses it into segments, and returns the serialized result based on the Manager configuration. It returns the combined result as a string.

func (*Manager) Service added in v0.2.5

func (m *Manager) Service()

Service initializes and runs the main web service for the application. It sets up middlewares, routes and starts the HTTP server.

type MdnsItem added in v0.3.2

type MdnsItem struct {
	GeoISP string   // Geolocation ISP information.
	IP     string   // IP address.
	CNAME  []string // CNAME records.
	Result []string // IP resolution results.
}

MdnsItem represents a single item in the MDNS response, containing relevant DNS information.

type MdnsResponse added in v0.3.2

type MdnsResponse struct {
	Domain string     // Queried domain.
	Items  []MdnsItem // List of MDNS items in the response.
}

MdnsResponse represents the response from an MDNS query.

type View added in v0.3.2

type View struct {
	GeoIPS string // Geolocation ISP information.
	IP     net.IP // Associated IP address.
}

View represents a geolocation view with associated IP and GeoISP information.

Jump to

Keyboard shortcuts

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