mirror of
https://github.com/nadoo/glider.git
synced 2025-02-24 01:45:39 +08:00
conn: add the ability to get outbound ip
This commit is contained in:
parent
824c9b3788
commit
4670c9931e
14
conn.go
14
conn.go
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"io"
|
"io"
|
||||||
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -79,3 +80,16 @@ func timedCopy(dst net.PacketConn, target net.Addr, src net.PacketConn, timeout
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OutboundIP returns preferred outbound ip of this machine
|
||||||
|
func OutboundIP() net.IP {
|
||||||
|
conn, err := net.Dial("udp", "8.8.8.8:80")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
localAddr := conn.LocalAddr().(*net.UDPAddr)
|
||||||
|
|
||||||
|
return localAddr.IP
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user