mirror of
https://github.com/prestonTao/upnp.git
synced 2025-12-24 13:08:03 +08:00
Merge pull request #1 from somethingnew2-0/spelling
Fix spelling of Gateway
This commit is contained in:
@@ -61,7 +61,7 @@ func (this *AddPortMapping) buildRequest(localPort, remotePort int, protocol str
|
||||
bodyStr := body.BuildXML()
|
||||
|
||||
//请求
|
||||
request, _ := http.NewRequest("POST", "http://"+this.upnp.Geteway.Host+this.upnp.CtrlUrl,
|
||||
request, _ := http.NewRequest("POST", "http://"+this.upnp.Gateway.Host+this.upnp.CtrlUrl,
|
||||
strings.NewReader(bodyStr))
|
||||
request.Header = header
|
||||
request.Header.Set("Content-Length", strconv.Itoa(len([]byte(bodyStr))))
|
||||
|
||||
@@ -50,7 +50,7 @@ func (this *DelPortMapping) buildRequest(remotePort int, protocol string) *http.
|
||||
bodyStr := body.BuildXML()
|
||||
|
||||
//请求
|
||||
request, _ := http.NewRequest("POST", "http://"+this.upnp.Geteway.Host+this.upnp.CtrlUrl,
|
||||
request, _ := http.NewRequest("POST", "http://"+this.upnp.Gateway.Host+this.upnp.CtrlUrl,
|
||||
strings.NewReader(bodyStr))
|
||||
request.Header = header
|
||||
request.Header.Set("Content-Length", strconv.Itoa(len([]byte(bodyStr))))
|
||||
|
||||
@@ -26,14 +26,14 @@ func (this *DeviceDesc) BuildRequest() *http.Request {
|
||||
header := http.Header{}
|
||||
header.Set("Accept", "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2")
|
||||
header.Set("User-Agent", "preston")
|
||||
header.Set("Host", this.upnp.Geteway.Host)
|
||||
header.Set("Host", this.upnp.Gateway.Host)
|
||||
header.Set("Connection", "keep-alive")
|
||||
|
||||
//请求
|
||||
request, _ := http.NewRequest("GET", "http://"+this.upnp.Geteway.Host+this.upnp.Geteway.DeviceDescUrl, nil)
|
||||
request, _ := http.NewRequest("GET", "http://"+this.upnp.Gateway.Host+this.upnp.Gateway.DeviceDescUrl, nil)
|
||||
request.Header = header
|
||||
// request := http.Request{Method: "GET", Proto: "HTTP/1.1",
|
||||
// Host: this.upnp.Geteway.Host, Url: this.upnp.Geteway.DeviceDescUrl, Header: header}
|
||||
// Host: this.upnp.Gateway.Host, Url: this.upnp.Gateway.DeviceDescUrl, Header: header}
|
||||
return request
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ func (this *DeviceDesc) resolve(resultStr string) {
|
||||
content := string([]byte(token))
|
||||
|
||||
//找到提供端口映射的服务
|
||||
if content == this.upnp.Geteway.ServiceType {
|
||||
if content == this.upnp.Gateway.ServiceType {
|
||||
ISUpnpServer = true
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ func (this SearchGatewayReq) BuildRequest() *http.Request {
|
||||
body.AddChild(childOne)
|
||||
bodyStr := body.BuildXML()
|
||||
//请求
|
||||
request, _ := http.NewRequest("POST", "http://"+this.upnp.Geteway.Host+this.upnp.CtrlUrl,
|
||||
request, _ := http.NewRequest("POST", "http://"+this.upnp.Gateway.Host+this.upnp.CtrlUrl,
|
||||
strings.NewReader(bodyStr))
|
||||
request.Header = header
|
||||
request.Header.Set("Content-Length", strconv.Itoa(len([]byte(bodyStr))))
|
||||
|
||||
@@ -43,7 +43,7 @@ func (this *ExternalIPAddress) BuildRequest() *http.Request {
|
||||
|
||||
bodyStr := body.BuildXML()
|
||||
//请求
|
||||
request, _ := http.NewRequest("POST", "http://"+this.upnp.Geteway.Host+this.upnp.CtrlUrl,
|
||||
request, _ := http.NewRequest("POST", "http://"+this.upnp.Gateway.Host+this.upnp.CtrlUrl,
|
||||
strings.NewReader(bodyStr))
|
||||
request.Header = header
|
||||
request.Header.Set("Content-Length", strconv.Itoa(len([]byte(body.BuildXML()))))
|
||||
@@ -68,7 +68,7 @@ func (this *ExternalIPAddress) resolve(resultStr string) {
|
||||
// 处理字符数据(这里就是元素的文本)
|
||||
case xml.CharData:
|
||||
if ISexternalIP == true {
|
||||
this.upnp.GetewayOutsideIP = string([]byte(token))
|
||||
this.upnp.GatewayOutsideIP = string([]byte(token))
|
||||
return
|
||||
}
|
||||
default:
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
// "net/http"
|
||||
)
|
||||
|
||||
type Geteway struct {
|
||||
GetewayName string //网关名称
|
||||
type Gateway struct {
|
||||
GatewayName string //网关名称
|
||||
Host string //网关ip和端口
|
||||
DeviceDescUrl string //网关设备描述路径
|
||||
Cache string //cache
|
||||
@@ -37,7 +37,7 @@ func (this *SearchGateway) Send() bool {
|
||||
}
|
||||
this.resolve(result)
|
||||
|
||||
this.upnp.Geteway.ServiceType = "urn:schemas-upnp-org:service:WANIPConnection:1"
|
||||
this.upnp.Gateway.ServiceType = "urn:schemas-upnp-org:service:WANIPConnection:1"
|
||||
this.upnp.Active = true
|
||||
return true
|
||||
}
|
||||
@@ -95,7 +95,7 @@ func (this *SearchGateway) buildRequest() {
|
||||
}
|
||||
|
||||
func (this *SearchGateway) resolve(result string) {
|
||||
this.upnp.Geteway = &Geteway{}
|
||||
this.upnp.Gateway = &Gateway{}
|
||||
|
||||
lines := strings.Split(result, "\r\n")
|
||||
for _, line := range lines {
|
||||
@@ -106,15 +106,15 @@ func (this *SearchGateway) resolve(result string) {
|
||||
}
|
||||
switch strings.ToUpper(strings.Trim(strings.Split(nameValues[0], ":")[0], " ")) {
|
||||
case "ST":
|
||||
this.upnp.Geteway.ST = nameValues[1]
|
||||
this.upnp.Gateway.ST = nameValues[1]
|
||||
case "CACHE-CONTROL":
|
||||
this.upnp.Geteway.Cache = nameValues[1]
|
||||
this.upnp.Gateway.Cache = nameValues[1]
|
||||
case "LOCATION":
|
||||
urls := strings.Split(strings.Split(nameValues[1], "//")[1], "/")
|
||||
this.upnp.Geteway.Host = urls[0]
|
||||
this.upnp.Geteway.DeviceDescUrl = "/" + urls[1]
|
||||
this.upnp.Gateway.Host = urls[0]
|
||||
this.upnp.Gateway.DeviceDescUrl = "/" + urls[1]
|
||||
case "SERVER":
|
||||
this.upnp.Geteway.GetewayName = nameValues[1]
|
||||
this.upnp.Gateway.GatewayName = nameValues[1]
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ func SearchGateway() {
|
||||
fmt.Println(err.Error())
|
||||
} else {
|
||||
fmt.Println("本机ip地址:", upnpMan.LocalHost)
|
||||
fmt.Println("upnp设备地址:", upnpMan.Geteway.Host)
|
||||
fmt.Println("upnp设备地址:", upnpMan.Gateway.Host)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ func ExternalIPAddr() {
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
} else {
|
||||
fmt.Println("外网ip地址为:", upnpMan.GetewayOutsideIP)
|
||||
fmt.Println("外网ip地址为:", upnpMan.GatewayOutsideIP)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
12
upnp.go
12
upnp.go
@@ -74,11 +74,11 @@ func (this *MappingPortStruct) GetAllMapping() map[string][][]int {
|
||||
type Upnp struct {
|
||||
Active bool //这个upnp协议是否可用
|
||||
LocalHost string //本机ip地址
|
||||
GetewayInsideIP string //局域网网关ip
|
||||
GetewayOutsideIP string //网关公网ip
|
||||
GatewayInsideIP string //局域网网关ip
|
||||
GatewayOutsideIP string //网关公网ip
|
||||
OutsideMappingPort map[string]int //映射外部端口
|
||||
InsideMappingPort map[string]int //映射本机端口
|
||||
Geteway *Geteway //网关信息
|
||||
Gateway *Gateway //网关信息
|
||||
CtrlUrl string //控制请求url
|
||||
MappingPort MappingPortStruct //已经添加了的映射 {"TCP":[1990],"UDP":[1991]}
|
||||
}
|
||||
@@ -113,7 +113,7 @@ func (this *Upnp) deviceStatus() {
|
||||
|
||||
//查看设备描述,得到控制请求url
|
||||
func (this *Upnp) deviceDesc() (err error) {
|
||||
if this.GetewayInsideIP == "" {
|
||||
if this.GatewayInsideIP == "" {
|
||||
if err := this.SearchGateway(); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -135,7 +135,7 @@ func (this *Upnp) ExternalIPAddr() (err error) {
|
||||
eia := ExternalIPAddress{upnp: this}
|
||||
eia.Send()
|
||||
return nil
|
||||
// log.Println("获得公网ip地址为:", this.GetewayOutsideIP)
|
||||
// log.Println("获得公网ip地址为:", this.GatewayOutsideIP)
|
||||
}
|
||||
|
||||
//添加一个端口映射
|
||||
@@ -146,7 +146,7 @@ func (this *Upnp) AddPortMapping(localPort, remotePort int, protocol string) (er
|
||||
err = errTemp.(error)
|
||||
}
|
||||
}(err)
|
||||
if this.GetewayOutsideIP == "" {
|
||||
if this.GatewayOutsideIP == "" {
|
||||
if err := this.ExternalIPAddr(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user