|
@ -9,6 +9,7 @@ import ( |
|
|
"bytes" |
|
|
"bytes" |
|
|
"encoding/xml" |
|
|
"encoding/xml" |
|
|
"errors" |
|
|
"errors" |
|
|
|
|
|
"fmt" |
|
|
"io/ioutil" |
|
|
"io/ioutil" |
|
|
"net" |
|
|
"net" |
|
|
"net/http" |
|
|
"net/http" |
|
@ -324,12 +325,17 @@ func (n *upnpNAT) getExternalIPAddress() (info statusInfo, err error) { |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// GetExternalAddress returns an external IP. If GetExternalIPAddress action
|
|
|
|
|
|
// fails or IP returned is invalid, GetExternalAddress returns an error.
|
|
|
func (n *upnpNAT) GetExternalAddress() (addr net.IP, err error) { |
|
|
func (n *upnpNAT) GetExternalAddress() (addr net.IP, err error) { |
|
|
info, err := n.getExternalIPAddress() |
|
|
info, err := n.getExternalIPAddress() |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
addr = net.ParseIP(info.externalIpAddress) |
|
|
addr = net.ParseIP(info.externalIpAddress) |
|
|
|
|
|
if addr == nil { |
|
|
|
|
|
err = fmt.Errorf("Failed to parse IP: %v", info.externalIpAddress) |
|
|
|
|
|
} |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|