File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed
Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change 11package lib
22
33import (
4+ "context"
45 "errors"
56 "fmt"
67 "io"
@@ -195,9 +196,27 @@ func (helper *IPHelper) getCurrentIP() {
195196
196197// getIPOnline gets public IP from internet.
197198func (helper * IPHelper ) getIPOnline () string {
199+ transport := & http.Transport {
200+ DialContext : func (ctx context.Context , _ , addr string ) (net.Conn , error ) {
201+ proto := "tcp"
202+
203+ if strings .ToUpper (helper .configuration .IPType ) == utils .IPV4 {
204+ // Force the network to "tcp4" to use only IPv4
205+ proto = "tcp4"
206+ }
207+
208+ return (& net.Dialer {
209+ Timeout : time .Second * utils .DefaultTimeout ,
210+ KeepAlive : 30 * time .Second ,
211+ }).DialContext (ctx , proto , addr )
212+ },
213+ }
214+
198215 client := & http.Client {
199- Timeout : time .Second * utils .DefaultTimeout ,
216+ Timeout : time .Second * utils .DefaultTimeout ,
217+ Transport : transport ,
200218 }
219+
201220 var onlineIP string
202221
203222 for {
You can’t perform that action at this time.
0 commit comments