haiwai-grlogs/logs/alils/sys.go

48 lines
840 B
Go
Raw Permalink Normal View History

2020-05-04 21:10:20 +08:00
package alils
import (
"fmt"
"net"
"os"
)
func GetCurrentInterface() *net.Interface {
if inter, err := net.InterfaceByName("eth0"); err == nil {
return inter
} else if inter, err := net.InterfaceByName("en0"); err == nil {
return inter
}
return nil
}
func GetCurrentInterfaceHardwareAddr() string {
if inter := GetCurrentInterface(); inter != nil {
return fmt.Sprintf("%s", inter.HardwareAddr)
}
return ""
}
func GetCurrentInterfaceAddrs() string {
if inter := GetCurrentInterface(); inter != nil {
if addrs, err := inter.Addrs(); err == nil {
return fmt.Sprintf("%s", addrs)
}
}
return ""
}
func GetHostname() string {
hostname, _ := os.Hostname()
return hostname
}
func GetUserHomename() string {
homedir, _ := os.UserHomeDir()
return homedir
}
func Getwd() string {
wd, _ := os.Getwd()
return wd
}