utils

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 21 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AwaitServiceRunning added in v0.5.0

func AwaitServiceRunning(name string, timeout time.Duration) error

AwaitServiceRunning waits until the given service exists and is running, e.g. a driver service installed on demand.

func CheckTestSigningAttribute added in v0.2.3

func CheckTestSigningAttribute(provider CmdOutputProvider) (bool, error)

func CondenseNetWithPortRange

func CondenseNetWithPortRange(nwps []akn.NetWithPortRange, limit int) []akn.NetWithPortRange

CondenseNetWithPortRange condenses a list of NetWithPortRange The way this algorithm works: 1. Sort the nwp list ascending by BaseIP and port 2. For each nwp in the list create a new nwp with the next neighbor if port-ranges are compatible 3. From the new list choose the nwp with the longest prefix length, remove all nwp witch are included in the chosen and add the chosen nwp to the result list 4. Repeat 3. until either the list is shorter than limit or no more compatible nwp are found

func ExecutePowershellCommand

func ExecutePowershellCommand(ctx context.Context, cmds []string) (string, error)

ExecutePowershellCommand runs the given commands in a powershell session. Callers must make sure that passed in commands are properly sanitizes.

func FindProcessIds added in v0.5.0

func FindProcessIds(processOrPid string) []int

FindProcessIds returns the given pid, or the pids of all processes whose executable name contains processOrPid.

func GetAvailableDriveLetters added in v0.2.0

func GetAvailableDriveLetters() ([]string, error)

func GetDriveSpace added in v0.2.0

func GetDriveSpace(driveLetter string) (free uint64, total uint64, err error)

GetDriveSpace returns the free and the total bytes of the given drive.

func IsExecutableOperational added in v0.2.0

func IsExecutableOperational(executableName string, args ...string) error

func IsProcessRunning added in v0.2.0

func IsProcessRunning(processName string) (bool, error)

IsProcessRunning reports whether a process with the given name is running. Like Get-Process -Name, the name is matched case-insensitively against the executable name without its ".exe" extension.

func IsTestSigningEnabled added in v0.2.3

func IsTestSigningEnabled() (bool, error)

func IsWindowsHomeEdition added in v0.5.0

func IsWindowsHomeEdition() bool

IsWindowsHomeEdition reports whether Windows runs as a Home edition, which does not apply policy-based QoS.

func MapToNetworks

func MapToNetworks(ctx context.Context, ipsOrCidrsOrHostnames ...string) ([]net.IPNet, error)

func ParsePortRanges

func ParsePortRanges(raw []string) ([]akn.PortRange, error)

func PowershellCommand added in v0.2.0

func PowershellCommand(args ...string) *exec.Cmd

func Resolve

func Resolve(ctx context.Context, hostnames ...string) ([]net.IP, error)

func ShiftSystemTime added in v0.5.0

func ShiftSystemTime(offset time.Duration) error

ShiftSystemTime moves the system clock by the given offset.

func StartService added in v0.5.0

func StartService(name string, timeout time.Duration) error

StartService starts the given Windows service and waits until it is running. A running service is left as is.

func StopProcess added in v0.2.0

func StopProcess(processName string) error

StopProcess forcefully terminates all processes with the given name, see IsProcessRunning for the matching.

func StopProcesses added in v0.5.0

func StopProcesses(pids []int, force bool) error

func StopService added in v0.5.0

func StopService(name string, timeout time.Duration) error

StopService stops the given Windows service and waits until it is stopped. A stopped service is left as is. A service that does not exist yields windows.ERROR_SERVICE_DOES_NOT_EXIST.

func SystemExecutable added in v0.5.0

func SystemExecutable(name string) string

SystemExecutable returns the absolute path of a tool in the Windows system directory, so that no executable with the same name found earlier in PATH is started instead.

Types

type CmdOutputProvider added in v0.2.3

type CmdOutputProvider func() ([]byte, error)

type HostnameInput

type HostnameInput struct {
	Records  []string
	Hostname string
}

func (*HostnameInput) Resolve

func (i *HostnameInput) Resolve(_ context.Context) (*HostnameOutput, error)

Resolve queries the Windows DNS client like Resolve-DnsName does, including the hosts file, the DNS cache and LLMNR/NetBIOS for local names.

type HostnameOutput

type HostnameOutput struct {
	IPAddresses []net.IP
}

type HostnameResolver

type HostnameResolver struct {
}

func (*HostnameResolver) Resolve

func (h *HostnameResolver) Resolve(ctx context.Context, hostnames ...string) ([]net.IP, error)

Jump to

Keyboard shortcuts

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