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.
23 lines
495 B
23 lines
495 B
package controller
|
|
|
|
import (
|
|
"net"
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func AddressesController(c *gin.Context) {
|
|
addrs, _ := net.InterfaceAddrs()
|
|
var result []string
|
|
for _, address := range addrs {
|
|
// check the address type and if it is not a loopback the display it
|
|
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
|
|
if ipnet.IP.To4() != nil {
|
|
result = append(result, ipnet.IP.String())
|
|
}
|
|
}
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"addresses": result})
|
|
}
|