Skip to content

Instantly share code, notes, and snippets.

@serverhorror
Created June 2, 2014 17:21
Show Gist options
  • Select an option

  • Save serverhorror/a653807202a6e58f3dfd to your computer and use it in GitHub Desktop.

Select an option

Save serverhorror/a653807202a6e58f3dfd to your computer and use it in GitHub Desktop.
(Some) Linux HW Info with golang
package main
import (
"encoding/json"
"fmt"
"log"
"net"
)
func main() {
ifaces, err := net.Interfaces()
if err != nil {
log.Printf("Error: %s", err)
}
for _, iface := range ifaces {
fmt.Printf("IFACE:\t%v\n", iface)
fmt.Printf("\tIndex: %v\n", iface.Index)
fmt.Printf("\tMTU: %v\n", iface.MTU)
fmt.Printf("\tName: %v\n", iface.Name)
fmt.Printf("\tHardwareAddr: %v\n", iface.HardwareAddr)
fmt.Printf("\tFlags: %s\n", iface.Flags)
addrs, _ := iface.Addrs()
fmt.Printf("\t\tAddresses: %s\n", addrs)
mcastAddrs, _ := iface.MulticastAddrs()
fmt.Printf("\t\tMulticastAddrs: %s\n", mcastAddrs)
}
for _, iface := range ifaces {
data, err := json.MarshalIndent(iface, "", " ")
if err != nil {
log.Printf("Error: %s", err)
}
fmt.Printf("%s\n", data)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment