GithubHelp home page GithubHelp logo

prestontao / upnp Goto Github PK

View Code? Open in Web Editor NEW
151.0 11.0 50.0 1.74 MB

A simple implements UPnP protocol for Go(Golang) library. Add port mapping for NAT devices. 在内网中搜索网关设备,检查网关是否支持upnp协议,若支持,添加端口映射。

Go 100.00%

upnp's Introduction

upnp protocol

====

A simple implements UPnP protocol for Golang library. Add port mapping for NAT devices.

在内网中搜索网关设备,检查网关是否支持upnp协议,若支持,添加端口映射。

====

example:

1. add a port mapping

mapping := new(upnp.Upnp)
if err := mapping.AddPortMapping(55789, 55789, "TCP"); err == nil {
	fmt.Println("success !")
	// remove port mapping in gatway
	mapping.Reclaim()
} else {
	fmt.Println("fail !")
}

2. search gateway device.

upnpMan := new(upnp.Upnp)
err := upnpMan.SearchGateway()
if err != nil {
	fmt.Println(err.Error())
} else {
	fmt.Println("local ip address: ", upnpMan.LocalHost)
	fmt.Println("gateway ip address: ", upnpMan.Gateway.Host)
}

3. get an internet ip address in gatway.

upnpMan := new(upnp.Upnp)
err := upnpMan.ExternalIPAddr()
if err != nil {
	fmt.Println(err.Error())
} else {
	fmt.Println("internet ip address: ", upnpMan.GatewayOutsideIP)
}

upnp's People

Contributors

prestontao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

upnp's Issues

upnp模块报错了 runtime error: invalid memory address or nil pointer dereference

Hi

I'm using your libraries for one of my projects, and I get this error from the libraries:

upnp模块报错了 runtime error: invalid memory address or nil

To riproduce it, I just run this code:

mapping_http := new(upnp.Upnp)
log.Printf("[INFO] UPnP on TCP %d...", ClusterPort)
if err := mapping_http.AddPortMapping(ClusterPort, ClusterPort, "TCP"); err == nil {
    log.Printf("[INFO] UPnP redirect TCP %d successful", ClusterPort)
} else {
    log.Printf("[WARNING] No UPnP on TCP %d: network UPnP-agnostic", ClusterPort)
}

log.Printf("[INFO] UPnP on UDP %d...", ClusterPort)

if err := mapping_http.AddPortMapping(ClusterPort, ClusterPort, "UDP"); err == nil {
    log.Printf("[INFO] UPnP redirect UDP %d successful", ClusterPort)
} else {
    log.Printf("[WARNING] No UPnP on UDP %d: network UPnP-agnostic", ClusterPort)
}

The complete log of this piece of code is:

2015/04/30 20:34:35 [INFO] UPnP on TCP 21000...
2015/04/30 20:35:05 upnp模块报错了 runtime error: invalid memory address or nil pointer dereference
2015/04/30 20:35:05 [INFO] UPnP redirect TCP 21000 successful
2015/04/30 20:35:05 [INFO] UPnP on UDP 21000...
2015/04/30 20:35:35 upnp模块报错了 runtime error: invalid memory address or nil pointer dereference
2015/04/30 20:35:35 [INFO] UPnP redirect UDP 21000 successful

as you can see, the port is opened and it returns no error. But it logs the message mentioned.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.