Protocol as param

This commit is contained in:
Durand Fabrice
2020-12-22 16:24:13 -05:00
parent 8c8c0d8962
commit bcc73e2a61
2 changed files with 6 additions and 6 deletions

View File

@@ -14,8 +14,8 @@ type GetListOfPortMappings struct {
upnp *Upnp
}
func (this *GetListOfPortMappings) Send() []PortMappingEntry {
request := this.buildRequest()
func (this *GetListOfPortMappings) Send(protocol string) []PortMappingEntry {
request := this.buildRequest(protocol)
response, _ := http.DefaultClient.Do(request)
resultBody, _ := ioutil.ReadAll(response.Body)
if response.StatusCode == 200 {
@@ -29,7 +29,7 @@ func (this *GetListOfPortMappings) Send() []PortMappingEntry {
return nil
}
func (this *GetListOfPortMappings) buildRequest() *http.Request {
func (this *GetListOfPortMappings) buildRequest(protocol string) *http.Request {
//请求头
header := http.Header{}
header.Set("Accept", "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2")
@@ -47,7 +47,7 @@ func (this *GetListOfPortMappings) buildRequest() *http.Request {
Attr: map[string]string{"xmlns:m": `"urn:schemas-upnp-org:service:WANIPConnection:2"`}}
childList1 := Node{Name: "NewStartPort", Content: "1"}
childList2 := Node{Name: "NewEndPort", Content: "65535"}
childList3 := Node{Name: "NewProtocol", Content: "UDP"}
childList3 := Node{Name: "NewProtocol", Content: protocol}
childList4 := Node{Name: "NewManage", Content: "1"}
childList5 := Node{Name: "NewNumberOfPorts", Content: "65535"}

View File

@@ -150,9 +150,9 @@ func (this *Upnp) DelPortMapping(remotePort int, protocol string) bool {
return issuccess
}
func (this *Upnp) GetListOfPortMappings() []PortMappingEntry {
func (this *Upnp) GetListOfPortMappings(protocol string) []PortMappingEntry {
listPort := GetListOfPortMappings{upnp: this}
portmap := listPort.Send()
portmap := listPort.Send(protocol)
return portmap
}