Moscato_DemoClient
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

getIpaddr.go 534B

1234567891011121314151617181920212223242526272829
  1. package main
  2. import (
  3. "fmt"
  4. "net"
  5. )
  6. func getCurrentIPAddr() string {
  7. addrs, err := net.InterfaceAddrs()
  8. if err != nil {
  9. fmt.Println(err)
  10. }
  11. var currentIP string
  12. for _, address := range addrs {
  13. // check the address type and if it is not a loopback the display it
  14. // = GET LOCAL IP ADDRESS
  15. if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
  16. if ipnet.IP.To4() != nil {
  17. //fmt.Println("Current IP address : ", ipnet.IP.String())
  18. currentIP = ipnet.IP.String()
  19. }
  20. }
  21. }
  22. return currentIP
  23. }