| 1234567891011121314151617181920212223242526272829 |
- package main
-
- import (
- "fmt"
- "net"
- )
-
- func getCurrentIPAddr() string {
- addrs, err := net.InterfaceAddrs()
-
- if err != nil {
- fmt.Println(err)
- }
-
- var currentIP string
-
- for _, address := range addrs {
-
- // check the address type and if it is not a loopback the display it
- // = GET LOCAL IP ADDRESS
- if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
- if ipnet.IP.To4() != nil {
- //fmt.Println("Current IP address : ", ipnet.IP.String())
- currentIP = ipnet.IP.String()
- }
- }
- }
- return currentIP
- }
|