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
+10.6k Golang : ISO8601 Duration Parser example
+10.3k Golang : How to check if a website is served via HTTPS
+9.5k Mac OSX : Get a process/daemon status information
+12.7k Golang : zlib compress file example
+9.9k Golang : Sort and reverse sort a slice of integers
+5.8k Unix/Linux : How to test user agents blocked successfully ?
+6.9k Mac/Linux/Windows : Get CPU information from command line
+10.1k Golang : How to get quoted string into another string?
+25.3k Golang : Get current file path of a file or executable
+6.3k Golang : Extract sub-strings
+18.6k Golang : Find IP address from string
+9.6k Golang : How to extract video or image files from html source code