use github.com/wlynxg/anet package

may fix #253
This commit is contained in:
nikk gitanes
2025-01-25 08:59:47 +03:00
parent f2ffd092ff
commit 95bbf831f5
6 changed files with 12 additions and 6 deletions

View File

@@ -44,7 +44,7 @@ GOBIN="go"
$GOBIN version $GOBIN version
LDFLAGS="'-s -w'" LDFLAGS="'-s -w -checklinkname=0'"
FAILURES="" FAILURES=""
ROOT=${PWD} ROOT=${PWD}
OUTPUT="${ROOT}/dist/TorrServer" OUTPUT="${ROOT}/dist/TorrServer"

View File

@@ -13,6 +13,7 @@ import (
"github.com/anacrolix/dms/dlna/dms" "github.com/anacrolix/dms/dlna/dms"
"github.com/anacrolix/log" "github.com/anacrolix/log"
"github.com/wlynxg/anet"
"server/settings" "server/settings"
"server/web/pages/template" "server/web/pages/template"
@@ -26,7 +27,7 @@ func Start() {
Logger: logger.WithNames("dms", "server"), Logger: logger.WithNames("dms", "server"),
Interfaces: func() (ifs []net.Interface) { Interfaces: func() (ifs []net.Interface) {
var err error var err error
ifaces, err := net.Interfaces() ifaces, err := anet.Interfaces()
if err != nil { if err != nil {
logger.Levelf(log.Error, "%v", err) logger.Levelf(log.Error, "%v", err)
return return
@@ -171,7 +172,7 @@ func getDefaultFriendlyName() string {
} }
if host == "localhost" { // useless host, use 1st IP if host == "localhost" { // useless host, use 1st IP
ifaces, err := net.Interfaces() ifaces, err := anet.Interfaces()
if err != nil { if err != nil {
return ret + ": " + userName + "@" + host return ret + ": " + userName + "@" + host
} }

View File

@@ -23,6 +23,7 @@ require (
github.com/swaggo/files v1.0.1 github.com/swaggo/files v1.0.1
github.com/swaggo/gin-swagger v1.6.0 github.com/swaggo/gin-swagger v1.6.0
github.com/swaggo/swag v1.16.3 github.com/swaggo/swag v1.16.3
github.com/wlynxg/anet v0.0.5
go.etcd.io/bbolt v1.3.10 go.etcd.io/bbolt v1.3.10
golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc
golang.org/x/image v0.18.0 golang.org/x/image v0.18.0

View File

@@ -338,6 +338,8 @@ github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65E
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/willf/bitset v1.1.9/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4= github.com/willf/bitset v1.1.9/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4=
github.com/willf/bitset v1.1.10/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4= github.com/willf/bitset v1.1.10/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4=
github.com/wlynxg/anet v0.0.5 h1:J3VJGi1gvo0JwZ/P1/Yc/8p63SoW98B5dHkYDmpgvvU=
github.com/wlynxg/anet v0.0.5/go.mod h1:eay5PRQr7fIVAMbTbchTnO9gG65Hg/uYGdc7mguHxoA=
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.etcd.io/bbolt v1.3.10 h1:+BqfJTcCzTItrop8mq/lbzL8wSGtj94UO/3U31shqG0= go.etcd.io/bbolt v1.3.10 h1:+BqfJTcCzTItrop8mq/lbzL8wSGtj94UO/3U31shqG0=

View File

@@ -10,6 +10,7 @@ import (
"github.com/anacrolix/publicip" "github.com/anacrolix/publicip"
"github.com/anacrolix/torrent" "github.com/anacrolix/torrent"
"github.com/anacrolix/torrent/metainfo" "github.com/anacrolix/torrent/metainfo"
"github.com/wlynxg/anet"
"server/settings" "server/settings"
"server/torr/storage/torrstor" "server/torr/storage/torrstor"
@@ -207,7 +208,7 @@ func isPrivateIP(ip net.IP) bool {
} }
func getPublicIp4() net.IP { func getPublicIp4() net.IP {
ifaces, err := net.Interfaces() ifaces, err := anet.Interfaces()
if err != nil { if err != nil {
log.Println("Error get public IPv4") log.Println("Error get public IPv4")
return nil return nil
@@ -233,7 +234,7 @@ func getPublicIp4() net.IP {
} }
func getPublicIp6() net.IP { func getPublicIp6() net.IP {
ifaces, err := net.Interfaces() ifaces, err := anet.Interfaces()
if err != nil { if err != nil {
log.Println("Error get public IPv6") log.Println("Error get public IPv6")
return nil return nil

View File

@@ -10,6 +10,7 @@ import (
"github.com/gin-contrib/cors" "github.com/gin-contrib/cors"
"github.com/gin-contrib/location" "github.com/gin-contrib/location"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/wlynxg/anet"
"server/dlna" "server/dlna"
"server/settings" "server/settings"
@@ -139,7 +140,7 @@ func echo(c *gin.Context) {
} }
func getLocalIps() []string { func getLocalIps() []string {
ifaces, err := net.Interfaces() ifaces, err := anet.Interfaces()
if err != nil { if err != nil {
log.TLogln("Error get local IPs") log.TLogln("Error get local IPs")
return nil return nil