interface.go 722 B

12345678910111213141516171819202122232425262728293031
  1. package configs
  2. import (
  3. "gopkg.in/ini.v1"
  4. )
  5. const ipconffile = "/etc/asterisk/dev_ip.conf"
  6. type NetworkInterface struct {
  7. Key string `json:"key"`
  8. Value string `json:"value"`
  9. Name string `json:"name"`
  10. }
  11. func GetNetworkInterface() []NetworkInterface {
  12. interfaces := make([]NetworkInterface, 0)
  13. cfg, err := ini.Load(ipconffile)
  14. if err != nil {
  15. return interfaces
  16. }
  17. keys := cfg.Section("interface").Keys()
  18. for _, key := range keys {
  19. if key.Name() == "eth0" {
  20. interfaces = append(interfaces, NetworkInterface{Key: key.Name(), Value: key.Value(), Name: "WAN"})
  21. } else {
  22. interfaces = append(interfaces, NetworkInterface{Key: key.Name(), Value: key.Value(), Name: "LAN"})
  23. }
  24. }
  25. return interfaces
  26. }