Update server.go

This commit is contained in:
Tara Rostami 2024-02-14 17:48:54 +03:30 committed by GitHub
parent 7d7385cc22
commit d83b12457b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -74,9 +74,8 @@ type Status struct {
Recv uint64 `json:"recv"`
} `json:"netTraffic"`
PublicIP struct {
HostName string `json:"hostname"`
IPv4 string `json:"ipv4"`
IPv6 string `json:"ipv6"`
IPv4 string `json:"ipv4"`
IPv6 string `json:"ipv6"`
} `json:"publicIP"`
AppStats struct {
Threads uint32 `json:"threads"`
@ -210,22 +209,8 @@ func (s *ServerService) GetStatus(lastStatus *Status) *Status {
logger.Warning("get udp connections failed:", err)
}
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 + " "
}
}
}
}
status.PublicIP.IPv4 = getPublicIP("https://api.ipify.org")
status.PublicIP.IPv6 = getPublicIP("https://api6.ipify.org")
if s.xrayService.IsXrayRunning() {
status.Xray.State = Running