48 line
837 B
Go
48 line
837 B
Go
package es
|
|
|
|
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
|
|
}
|