Add timeout to GetPublicIP func
This commit is contained in:
+10
-1
@@ -63,11 +63,20 @@ func LookupIP(address string) (string, error) {
|
|||||||
|
|
||||||
// GetPublicIP example from https://github.com/pion/stun
|
// GetPublicIP example from https://github.com/pion/stun
|
||||||
func GetPublicIP() (net.IP, error) {
|
func GetPublicIP() (net.IP, error) {
|
||||||
c, err := stun.Dial("udp", "stun.l.google.com:19302")
|
conn, err := net.Dial("udp", "stun.l.google.com:19302")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c, err := stun.NewClient(conn)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = conn.SetDeadline(time.Now().Add(time.Second * 3)); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
var res stun.Event
|
var res stun.Event
|
||||||
|
|
||||||
message := stun.MustBuild(stun.TransactionID, stun.BindingRequest)
|
message := stun.MustBuild(stun.TransactionID, stun.BindingRequest)
|
||||||
|
|||||||
Reference in New Issue
Block a user