net

package
v0.0.0-...-81d58bd Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2024 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckInternetConnectivity

func CheckInternetConnectivity() bool

CheckInternetConnectivity checks if the system has internet connectivity by attempting to resolve the IP address of a well-known hostname (e.g., Google's public DNS).

Example:

if net.CheckInternetConnectivity() {
	fmt.Println("Internet connectivity is available")
} else {
	fmt.Println("Internet connectivity is not available")
}

Notes:

this function is a simple wrapper around ResolveIPAddress().

func CheckPortStatus

func CheckPortStatus(host string, port int) types.PortStatus

CheckPortStatus checks the status of a given port on a specific host.

Example:

import netTypes "github.com/vanilla-os/sdk/pkg/v1/net/types"

portStatus := net.CheckPortStatus("vanilla.org", 80)
if portStatus == netTypes.PortOpen {
	fmt.Println("Port is open")
} else {
	fmt.Println("Port is closed")
}

func GetActiveConnections

func GetActiveConnections() ([]types.ConnectionInfo, error)

GetActiveConnections returns information about active network connections.

Example:

connInfos, err := net.GetActiveConnections()
if err != nil {
	fmt.Printf("Error: %v\n", err)
	return
}

for _, connInfo := range connInfos {
	fmt.Printf("Local address: %s\n", connInfo.LocalAddr)
	fmt.Printf("Remote address: %s\n", connInfo.RemoteAddr)
	fmt.Printf("State: %s\n", connInfo.State)
}

func GetDNSInfo

func GetDNSInfo(hostname string) (*types.DNSInfo, error)

GetDNSInfo resolves a hostname to its corresponding IP addresses.

Example:

dnsInfo, err := net.GetDNSInfo("vanilla.org")
if err != nil {
	fmt.Printf("Error: %v\n", err)
	return
}

fmt.Printf("Hostname: %s\n", dnsInfo.Hostname)
fmt.Printf("IP addresses: %v\n", dnsInfo.IPAddresses)

func GetDefaultGateway

func GetDefaultGateway() (string, error)

GetDefaultGateway retrieves the default gateway IP address.

Example:

gateway, err := net.GetDefaultGateway()
if err != nil {
	fmt.Printf("Error: %v\n", err)
	return
}

fmt.Printf("Default gateway: %s\n", gateway)

Notes:

this function relies on the 'ip' command

func GetInterfaceIPAddresses

func GetInterfaceIPAddresses(interfaceName string) ([]string, error)

GetInterfaceIPAddresses returns the IP addresses associated with a specific network interface.

Example:

ipAddresses, err := net.GetInterfaceIPAddresses("eth0")
if err != nil {
	fmt.Printf("Error: %v\n", err)
	return
}

for _, ip := range ipAddresses {
	fmt.Printf("IP address: %s\n", ip)
}

func GetNetworkInterfaces

func GetNetworkInterfaces() ([]types.NetworkInterfaceInfo, error)

GetNetworkInterfaces returns a list of network interfaces available on the system.

Example:

interfaces, err := net.GetNetworkInterfaces()
if err != nil {
	fmt.Printf("Error: %v\n", err)
	return
}

for _, iface := range interfaces {
	fmt.Printf("Name: %s\n", iface.Name)
	fmt.Printf("Hardware address: %s\n", iface.HardwareAddr)
	fmt.Printf("IP addresses: %v\n", iface.IPAddresses)
}

func IsLocalNetworkIP

func IsLocalNetworkIP(ipAddress string) bool

IsLocalNetworkIP checks if the given IP address belongs to a local network.

Example:

if net.IsLocalNetworkIP("
	fmt.Println("IP address belongs to a local network")
} else {
	fmt.Println("IP address does not belong to a local network")
}

func ResolveIPAddress

func ResolveIPAddress(hostname string) (string, error)

ResolveIPAddress resolves the IP address of a given hostname.

Example:

ipAddress, err := net.ResolveIPAddress("vanilla.org")
if err != nil {
	fmt.Printf("Error: %v\n", err)
	return
}

fmt.Printf("IP address: %s\n", ipAddress)

func ResolveMACAddress

func ResolveMACAddress(ipAddress string) (string, error)

ResolveMACAddress resolves the MAC address for a given IP address.

Example:

macAddress, err := net.ResolveMACAddress("
if err != nil {
	fmt.Printf("Error: %v\n", err)
	return
}

fmt.Printf("MAC address: %s\n", macAddress)

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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