Overview
TheInterfaces function retrieves detailed information about all network interfaces installed on the system, including physical and virtual interfaces.
Functions
Parameters
Context for cancellation and timeout control
Returns
Returns anInterfaceStatList (slice of InterfaceStat) containing information about each network interface.
InterfaceStat Structure
TheInterfaceStat struct contains comprehensive information about a network interface.
Fields
The interface index, a unique identifier for the interface.
Maximum Transmission Unit - the maximum size of a packet that can be transmitted through this interface (in bytes).
The interface name. Examples:
- Linux:
"eth0","wlan0","lo" - macOS:
"en0","lo0","awdl0" - Windows:
"Ethernet","Wi-Fi"
Hardware (MAC) address in IEEE MAC-48, EUI-48, or EUI-64 format (e.g.,
"00:11:22:33:44:55").List of interface flags indicating the interface state and capabilities. Common flags:
"up"- Interface is administratively up"broadcast"- Interface supports broadcast"loopback"- Loopback interface"pointtopoint"- Point-to-point link"multicast"- Interface supports multicast
List of IP addresses assigned to this interface.
InterfaceAddr Structure
TheInterfaceAddr struct represents an IP address assigned to an interface.
IP address in CIDR notation, including the subnet mask (e.g.,
"192.168.1.100/24", "fe80::1/64").Type Aliases
String() method for JSON serialization.
Usage Examples
List All Interfaces
Get Active Interfaces
Display Interface Addresses
Find Interface by Name
Check Interface Capabilities
Using Context
Get Non-Loopback Interfaces
Interface Flags
Common interface flags returned in theFlags field:
up
up
Interface is administratively up and operational.
broadcast
broadcast
Interface supports broadcast addressing (can send packets to all devices on the network).
loopback
loopback
Loopback interface (typically
lo or lo0), used for local communication.pointtopoint
pointtopoint
Point-to-point link (e.g., PPP, VPN connections).
multicast
multicast
Interface supports multicast addressing.
Platform-Specific Notes
Linux
- Interface names:
eth0,wlan0,enp0s3,wlp2s0,lo - Predictable network interface names may be used on modern systems
macOS
- Interface names:
en0,en1,lo0,awdl0,utun0 en0is typically the primary Ethernet/Wi-Fi interface
Windows
- Interface names are more descriptive:
Ethernet,Wi-Fi,Loopback Pseudo-Interface 1 - Names may be localized based on system language
BSD
- Similar naming to Linux but may have different interface types
- Interface indices are stable across reboots
Common Use Cases
- Network monitoring and diagnostics
- Discovering available network interfaces
- Checking interface configuration
- Determining MAC addresses for device identification
- Validating network connectivity
- Interface selection for network operations
See Also
- I/O Counters - Get I/O statistics for interfaces
- Connections - Monitor network connections
- Network Overview - Package overview