From f6ebe059057a2d7200de76bdc69a51552e1eadaf Mon Sep 17 00:00:00 2001 From: Tara Rostami <132676256+TaraRostami@users.noreply.github.com> Date: Wed, 14 Feb 2024 13:23:21 +0330 Subject: [PATCH] Update server.go --- web/service/server.go | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/web/service/server.go b/web/service/server.go index 822918a8..e7dccb81 100644 --- a/web/service/server.go +++ b/web/service/server.go @@ -74,8 +74,9 @@ type Status struct { Recv uint64 `json:"recv"` } `json:"netTraffic"` PublicIP struct { - IPv4 string `json:"ipv4"` - IPv6 string `json:"ipv6"` + HostName string `json:"hostname"` + IPv4 string `json:"ipv4"` + IPv6 string `json:"ipv6"` } `json:"publicIP"` AppStats struct { Threads uint32 `json:"threads"` @@ -209,8 +210,22 @@ func (s *ServerService) GetStatus(lastStatus *Status) *Status { logger.Warning("get udp connections failed:", err) } - status.PublicIP.IPv4 = getPublicIP("https://api.ipify.org") - status.PublicIP.IPv6 = getPublicIP("https://api6.ipify.org") + status.PublicIP.HostName, _ = os.Hostname() + // get ip address + netInterfaces, _ := net.Interfaces() + for i := 0; i < len(netInterfaces); i++ { + if len(netInterfaces[i].Flags) > 2 && netInterfaces[i].Flags[0] == "up" && netInterfaces[i].Flags[1] != "loopback" { + addrs := netInterfaces[i].Addrs + + for _, address := range addrs { + if strings.Contains(address.Addr, ".") { + status.PublicIP.IPv4 += address.Addr + " " + } else if address.Addr[0:6] != "fe80::" { + status.PublicIP.IPv6 += address.Addr + " " + } + } + } + } if s.xrayService.IsXrayRunning() { status.Xray.State = Running