高热共公日志库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
840 B

  1. package alils
  2. import (
  3. "fmt"
  4. "net"
  5. "os"
  6. )
  7. func GetCurrentInterface() *net.Interface {
  8. if inter, err := net.InterfaceByName("eth0"); err == nil {
  9. return inter
  10. } else if inter, err := net.InterfaceByName("en0"); err == nil {
  11. return inter
  12. }
  13. return nil
  14. }
  15. func GetCurrentInterfaceHardwareAddr() string {
  16. if inter := GetCurrentInterface(); inter != nil {
  17. return fmt.Sprintf("%s", inter.HardwareAddr)
  18. }
  19. return ""
  20. }
  21. func GetCurrentInterfaceAddrs() string {
  22. if inter := GetCurrentInterface(); inter != nil {
  23. if addrs, err := inter.Addrs(); err == nil {
  24. return fmt.Sprintf("%s", addrs)
  25. }
  26. }
  27. return ""
  28. }
  29. func GetHostname() string {
  30. hostname, _ := os.Hostname()
  31. return hostname
  32. }
  33. func GetUserHomename() string {
  34. homedir, _ := os.UserHomeDir()
  35. return homedir
  36. }
  37. func Getwd() string {
  38. wd, _ := os.Getwd()
  39. return wd
  40. }