tools

package
v0.1.31 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: BSD-2-Clause Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateDir

func CreateDir(dir string) (string, error)

CreateDir creates a directory if it does not exist, returning the final normalized directory as a result.

func CreateDirFromFilename added in v0.1.8

func CreateDirFromFilename(destination string, s string) (string, error)

func CreateFileWithDir

func CreateFileWithDir(destination string) (string, error)

CreateFileWithDir creates a file, relative to a directory, returning the final normalized path as a result.

func EncodeFileToBase64

func EncodeFileToBase64(filename string) (string, error)

func FileExists

func FileExists(path string) bool

FileExists returns true if a path exists

func Float64ToTime

func Float64ToTime(f float64) time.Time

Float64ToTime takes a float64 as number of seconds since unix epoch and returns time.Time

example field where this is used (expires field):

https://chromedevtools.github.io/devtools-protocol/tot/Network/#type-Cookie

func FormatInt

func FormatInt(n int) string

func FormatInt64

func FormatInt64(n int64) string

func GetDNSServers added in v0.1.10

func GetDNSServers() (nameservers []netip.AddrPort)

func GetDefaultDnsServer added in v0.1.10

func GetDefaultDnsServer(fallback string) string

func GetHash

func GetHash(data []byte) string

func GetMimeType added in v0.1.8

func GetMimeType(s string) (string, error)

func GetValidDnsSuffix

func GetValidDnsSuffix(dnsServer string, suffix string, proxyUri *url.URL) (string, error)

func GetZoneApexSuffix added in v0.1.27

func GetZoneApexSuffix(dnsServer string, suffix string, proxyUri *url.URL, allowPublicSuffix bool) (string, error)

GetZoneApexSuffix resolves the authoritative zone apex for a DNS name that is not necessarily a zone apex itself (e.g. www.example.com). It walks the name and each of its parent domains, from most to least specific, and returns the first candidate that is itself a zone apex (i.e. a SOA whose owner name equals the candidate). Requiring the SOA owner to match the candidate avoids honoring a SOA returned via a CNAME chase (e.g. www -> *.github.io), which would point at the target's zone instead of the queried name's own zone. Returns the apex with a trailing dot, matching GetValidDnsSuffix.

When allowPublicSuffix is false the walk stops (and fails) before reaching a public suffix such as com.br or co.uk, so registry-operated zones are never enumerated. Set allowPublicSuffix to true to explicitly permit them.

func HammingDistance

func HammingDistance(hash1, hash2 []byte) (int, error)

HammingDistance calculates the number of differing bits between two byte slices.

func HasBOM added in v0.1.8

func HasBOM(fileName string) bool

func IpToUint32 added in v0.1.17

func IpToUint32(ip net.IP) uint32

func IpsInCIDR

func IpsInCIDR(cidr string) ([]string, error)

IpsInCIDR returns a list of usable IP addresses in a given CIDR block excluding network and broadcast addresses for CIDRs larger than /31.

func IsPrivateIP added in v0.1.10

func IsPrivateIP(ipAddr string) bool

func IsPublicSuffix added in v0.1.28

func IsPublicSuffix(name string) bool

IsPublicSuffix reports whether name is itself a public suffix (an entry on the Public Suffix List, such as "com", "com.br" or "co.uk") — a registry-operated zone with no registrable label, which must never be enumerated as a target.

func LeftTrucate

func LeftTrucate(s string, max int) string

LeftTrucate a string if its more than max

func MoveFile

func MoveFile(sourcePath, destPath string) error

MoveFile moves a file from a to b

func ParsePerceptionHash

func ParsePerceptionHash(hashStr string) ([]byte, error)

ParsePerceptionHash converts a perception hash string "p:<hex>" to a byte slice.

func RandSleep added in v0.1.10

func RandSleep()

func RemoveFolder added in v0.1.8

func RemoveFolder(path string) error

func SafeFileName

func SafeFileName(s string) string

SafeFileName takes a string and returns a string safe to use as a file name.

func ShuffleStr

func ShuffleStr(slice []string)

ShuffleStr shuffles a slice of strings

func SliceHasInt

func SliceHasInt(slice []int, item int) bool

SliceHasInt checks if a slice has an int

func SliceHasStr

func SliceHasStr(slice []string, item string) bool

SliceHasStr checks if a slice has a string

func SliceHasUInt16 added in v0.1.9

func SliceHasUInt16(slice []uint16, item uint16) bool

SliceHasInt checks if a slice has an int

func TempFileName added in v0.1.8

func TempFileName(basePath, prefix, suffix string) string

func UnescapeDNSName added in v0.1.30

func UnescapeDNSName(s string) string

UnescapeDNSName converts a DNS name in miekg/dns presentation format back to its raw byte form. The DNS library escapes every byte that is not a printable ASCII label character: non-ASCII/non-printable bytes become a decimal "\DDD" sequence and the special characters '.' and '\' become "\." and "\\". An IDN label carrying raw UTF-8 (e.g. "sòdoc") is therefore handed to us as "s\195\178doc"; decoding the "\DDD" sequences rebuilds the original UTF-8 bytes so the name is stored readably instead of as escaped gibberish.

It is a no-op for names that contain no backslash (the overwhelming majority), so it is cheap to call on every name.

func UniqueIntSlice

func UniqueIntSlice(slice []int) []int

UniqueIntSlice returns a slice of unique ints

func Unzip added in v0.1.8

func Unzip(src, dest string) error

Types

type HammingGroup

type HammingGroup struct {
	GroupID uint
	Hash    []byte
}

HammingGroup represents a hash -> group assignment used for inmemory hammingdistance calulations.

Jump to

Keyboard shortcuts

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