Exemple #1
0
//获得公网ip地址
func ExternalIPAddr() {
	upnpMan := new(upnp.Upnp)
	err := upnpMan.ExternalIPAddr()
	if err != nil {
		fmt.Println(err.Error())
	} else {
		fmt.Println("外网ip地址为:", upnpMan.GatewayOutsideIP)
	}
}
Exemple #2
0
//添加一个端口映射
func AddPortMapping() {
	mapping := new(upnp.Upnp)
	if err := mapping.AddPortMapping(55789, 55789, "TCP"); err == nil {
		fmt.Println("端口映射成功")
		mapping.Reclaim()
	} else {
		fmt.Println("端口映射失败")
	}

}
Exemple #3
0
//搜索网关设备
func SearchGateway() {
	upnpMan := new(upnp.Upnp)
	err := upnpMan.SearchGateway()
	if err != nil {
		fmt.Println(err.Error())
	} else {
		fmt.Println("本机ip地址:", upnpMan.LocalHost)
		fmt.Println("upnp设备地址:", upnpMan.Gateway.Host)
	}
}