Auto detect public IPs if not provided by user

adopted code from anacrolix/confluence 3c7a0c445d
This commit is contained in:
nikk gitanes
2022-05-25 05:27:20 +03:00
parent a2fbd0ee80
commit 2df81cac78
4 changed files with 18 additions and 6 deletions

View File

@@ -30,7 +30,7 @@ func Start(port string) {
log.TLogln("Start TorrServer")
ips := getLocalIps()
if len(ips) > 0 {
log.TLogln("IPs:", ips)
log.TLogln("Local IPs:", ips)
}
err := BTS.Connect()
if err != nil {
@@ -102,7 +102,7 @@ func getLocalIps() []string {
case *net.IPAddr:
ip = v.IP
}
if !ip.IsLoopback() {
if !ip.IsLoopback() && !ip.IsLinkLocalUnicast() && !ip.IsLinkLocalMulticast() {
list = append(list, ip.String())
}
}