utils

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var TLSConfig = &tls.Config{
	InsecureSkipVerify: true,
	MinVersion:         tls.VersionTLS10,
}

Functions

func ContainsAny added in v0.1.1

func ContainsAny(s string, substrs ...string) bool

func CountLinesInFile

func CountLinesInFile(filename string) (int, error)

func GetInterfaceIPv4 added in v1.0.0

func GetInterfaceIPv4(name string) (net.IP, error)

GetInterfaceIPv4 returns the first IPv4 address bound to the named network interface. For loopback interfaces ("lo", "lo0") loopback addresses (127.x.x.x) are included. For all other interfaces loopback addresses are skipped. Returns an error if the interface does not exist or has no matching IPv4 address.

func GetTLSConfig

func GetTLSConfig() *tls.Config

GetTLSConfig returns a clone of the base TLS config so each caller can safely mutate fields (e.g. ServerName) without racing other callers.

func HasStdin added in v1.0.0

func HasStdin() bool

HasStdin returns true if data is being piped to stdin.

func IsFileExists

func IsFileExists(filePath string) bool

IsFileExists checks if a file exists at the given path.

func LoadLines added in v1.0.0

func LoadLines(filename string) []string

LoadLines reads all non-empty lines from a file into a slice. If filename is not a real file, it returns a single-element slice.

func LoadSSHKeyPaths added in v1.0.0

func LoadSSHKeyPaths(path string) []string

LoadSSHKeyPaths handles -p for the sshkey module. If the argument is a PEM key file (starts with "-----"), the path itself becomes the single entry. If it's a plain text file of key paths, each line is loaded. If it's not a file at all, it's returned as-is (could be raw PEM passed on the command line).

func LookupAddr

func LookupAddr(addr string) (net.IP, error)

func MD5Hex added in v1.0.0

func MD5Hex(s string) string

MD5Hex returns the lowercase hex-encoded MD5 hash of s.

func ParseFileByLine added in v0.1.1

func ParseFileByLine(filename string) <-chan string

ParseFileByLine is a function to read file in iterations

func ReadFull added in v1.0.0

func ReadFull(conn net.Conn, buf []byte) (int, error)

ReadFull reads exactly len(buf) bytes from conn. It retries short reads until the buffer is full or an error occurs.

Types

type CustomTransport added in v0.1.1

type CustomTransport struct {
	Transport http.RoundTripper
	UserAgent string
}

CustomTransport wraps http.Transport and adds a default User-Agent header.

func (*CustomTransport) RoundTrip added in v0.1.1

func (t *CustomTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements the http.RoundTripper interface. It is needed to make the HTTP requests look like browsers.

type ProxyAwareDialer

type ProxyAwareDialer struct {
	HTTPClient *http.Client
	UserAgent  string
	// contains filtered or unexported fields
}

func NewProxyAwareDialer

func NewProxyAwareDialer(proxyHost, proxyAuth string, timeout time.Duration, userAgent string, localAddr net.IP) (*ProxyAwareDialer, error)

NewProxyAwareDialer creates a dialer with optional SOCKS5 proxy and optional local address binding. localAddr binds outgoing connections to a specific interface IP (nil = OS default).

func (*ProxyAwareDialer) Dial

func (p *ProxyAwareDialer) Dial(network, addr string) (net.Conn, error)

func (*ProxyAwareDialer) DialAuto added in v1.0.0

func (p *ProxyAwareDialer) DialAuto(network, addr string, encryption bool) (net.Conn, error)

DialAuto dials using TLS or plaintext based on the encryption flag.

func (*ProxyAwareDialer) DialAutoContext added in v1.0.0

func (p *ProxyAwareDialer) DialAutoContext(ctx context.Context, network, addr string, encryption bool) (net.Conn, error)

DialAutoContext dials using TLS or plaintext based on the encryption flag, with context support.

func (*ProxyAwareDialer) DialContext

func (p *ProxyAwareDialer) DialContext(ctx context.Context, network, addr string) (net.Conn, error)

func (*ProxyAwareDialer) DialTLS

func (p *ProxyAwareDialer) DialTLS(network, addr string, config *tls.Config) (net.Conn, error)

DialTLS establishes a TLS connection through the proxy

func (*ProxyAwareDialer) DialTLSContext

func (p *ProxyAwareDialer) DialTLSContext(ctx context.Context, network, addr string, config *tls.Config) (net.Conn, error)

DialTLSContext establishes a TLS connection with context support

func (*ProxyAwareDialer) DialTimeout

func (p *ProxyAwareDialer) DialTimeout(network, addr string, timeout time.Duration) (net.Conn, error)

DialTimeout dials with a specific timeout (implements pq.Dialer interface)

func (*ProxyAwareDialer) Timeout

func (p *ProxyAwareDialer) Timeout() time.Duration

type TLSDialerWrapper

type TLSDialerWrapper struct {
	Dialer *ProxyAwareDialer
}

TLSDialerWrapper wraps ProxyAwareDialer to use TLS for all connections

func (*TLSDialerWrapper) Dial

func (w *TLSDialerWrapper) Dial(network, addr string) (net.Conn, error)

func (*TLSDialerWrapper) DialTimeout

func (w *TLSDialerWrapper) DialTimeout(network, addr string, timeout time.Duration) (net.Conn, error)

Jump to

Keyboard shortcuts

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