mirror of
https://github.com/inverse-inc/upnp.git
synced 2024-05-03 14:44:57 +08:00
24 lines
370 B
Go
24 lines
370 B
Go
|
package upnp
|
||
|
|
||
|
import (
|
||
|
"log"
|
||
|
"net"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
//获取本机能联网的ip地址
|
||
|
func GetLocalIntenetIp() string {
|
||
|
/*
|
||
|
获得所有本机地址
|
||
|
判断能联网的ip地址
|
||
|
*/
|
||
|
|
||
|
conn, err := net.Dial("udp", "google.com:80")
|
||
|
if err != nil {
|
||
|
log.Println(err.Error())
|
||
|
}
|
||
|
defer conn.Close()
|
||
|
ip := strings.Split(conn.LocalAddr().String(), ":")[0]
|
||
|
return ip
|
||
|
}
|