Menu Close

Go – InterfaceAddrs() of net package in go

InterfaceAddrs() function is used to return a list of the system’s unicast interface addresses of net package.

function prototype:

func InterfaceAddrs() ([]Addr, error)

Return type:

InterfaceAddrs() of net package in go returns type Addr interface.

type Addr interface {
	Network() string // name of the network (for example, "tcp", "udp")
	String() string  // string form of address (for example, "", "[2001:db8::1]:80")


package main

import (

func main() {
    addrs, err := net.InterfaceAddrs()
    if err != nil {
        log.Fatal("Error is: ", err)
    for _, addr := range addrs {
        fmt.Println("Network name: ", addr.Network())
        fmt.Println("address: ", addr.String())


Network name:  ip+net

To learn more about golang, Please refer given below link:


Posted in golang, net, packages

Leave a Reply

Your email address will not be published. Required fields are marked *