Golang net.Interfaces() function examples
package net
Golang net.Interfaces() function usage examples
Example 1:
package main
import (
"fmt"
"net"
)
func main() {
interfaces, err := net.Interfaces()
if err != nil {
fmt.Print(err)
return
}
for _, i := range interfaces {
fmt.Printf("Name : %v \n", i.Name)
// see http://golang.org/pkg/net/#Flags
fmt.Println("Interface type and supports : ", i.Flags.String())
}
}
Example 2:
ifaces, err := net.Interfaces()
if err != nil {
fmt.Print(err)
return
}
for _, i := range ifaces {
addrs, err := i.Addrs()
if err != nil {
fmt.Print(err)
continue
}
for _, a := range addrs {
switch v := a.(type) {
case *net.IPAddr:
fmt.Printf("%v : %s (%s)\n", i.Name, v, v.IP.DefaultMask())
}
}
}
References :
Advertisement
Something interesting
Tutorials
+25.3k Golang : Convert uint value to string type
+4.1k Javascript : Empty an array example
+7.5k SSL : How to check if current certificate is sha1 or sha2 from command line
+20k Golang : How to run your code only once with sync.Once object
+11.9k Golang : Convert(cast) bigint to string
+14.6k Golang : Execute function at intervals or after some delay
+5.7k Golang : ROT32768 (rotate by 0x80) UTF-8 strings example
+12.3k Golang : Flush and close file created by os.Create and bufio.NewWriter example
+25.7k Golang : missing Mercurial command
+9.4k Golang : Qt Yes No and Quit message box example
+12.1k Golang : Split strings into command line arguments
+6k Golang : Function as an argument type example