Documentation ¶
Index ¶
- func CheckInternetConnectivity() bool
- func CheckPortStatus(host string, port int) types.PortStatus
- func GetActiveConnections() ([]types.ConnectionInfo, error)
- func GetDNSInfo(hostname string) (*types.DNSInfo, error)
- func GetDefaultGateway() (string, error)
- func GetInterfaceIPAddresses(interfaceName string) ([]string, error)
- func GetNetworkInterfaces() ([]types.NetworkInterfaceInfo, error)
- func IsLocalNetworkIP(ipAddress string) bool
- func ResolveIPAddress(hostname string) (string, error)
- func ResolveMACAddress(ipAddress string) (string, error)
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.