Commit 034a635e authored by Steven Allen's avatar Steven Allen

Merge remote-tracking branch 'fd/master'

parents b1008fbf 51722233
......@@ -4,4 +4,5 @@ require (
github.com/huin/goupnp v1.0.0
github.com/jackpal/gateway v1.0.5
github.com/jackpal/go-nat-pmp v1.0.1
github.com/koron/go-ssdp v0.0.0-20180514024734-4a0ed625a78b
)
......@@ -41,6 +41,8 @@ func DiscoverGateway() (NAT, error) {
return nat, nil
case nat := <-discoverUPNP_IG2():
return nat, nil
case nat := <-discoverUPNP_GenIGDev():
return nat, nil
case nat := <-discoverNATPMP():
return nat, nil
case <-time.After(10 * time.Second):
......
......@@ -2,11 +2,15 @@ package nat
import (
"net"
"net/url"
"strings"
"time"
"github.com/huin/goupnp"
"github.com/huin/goupnp/dcps/internetgateway1"
"github.com/huin/goupnp/dcps/internetgateway2"
"github.com/koron/go-ssdp"
)
var (
......@@ -123,6 +127,62 @@ func discoverUPNP_IG2() <-chan NAT {
return res
}
func discoverUPNP_GenIGDev() <-chan NAT {
res := make(chan NAT, 1)
go func() {
DeviceList, err := ssdp.Search(ssdp.All, 5, "")
if err != nil {
return
}
var gw ssdp.Service
for _, Service := range DeviceList {
if strings.Contains(Service.Type, "InternetGatewayDevice") {
gw = Service
break
}
}
DeviceURL, err := url.Parse(gw.Location)
if err != nil {
return
}
RootDevice, err := goupnp.DeviceByURL(DeviceURL)
if err != nil {
return
}
RootDevice.Device.VisitServices(func(srv *goupnp.Service) {
switch srv.ServiceType {
case internetgateway1.URN_WANIPConnection_1:
client := &internetgateway1.WANIPConnection1{ServiceClient: goupnp.ServiceClient{
SOAPClient: srv.NewSOAPClient(),
RootDevice: RootDevice,
Service: srv,
}}
_, isNat, err := client.GetNATRSIPStatus()
if err == nil && isNat {
res <- &upnp_NAT{client, make(map[int]int), "UPNP (IG1-IP1)", RootDevice}
return
}
case internetgateway1.URN_WANPPPConnection_1:
client := &internetgateway1.WANPPPConnection1{ServiceClient: goupnp.ServiceClient{
SOAPClient: srv.NewSOAPClient(),
RootDevice: RootDevice,
Service: srv,
}}
_, isNat, err := client.GetNATRSIPStatus()
if err == nil && isNat {
res <- &upnp_NAT{client, make(map[int]int), "UPNP (IG1-PPP1)", RootDevice}
return
}
}
})
}()
return res
}
type upnp_NAT_Client interface {
GetExternalIPAddress() (string, error)
AddPortMapping(string, uint16, string, uint16, string, bool, string, uint32) error
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment