You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

github.com/micmonay/upnp

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/micmonay/upnp

v0.0.0-20160615095709-759385d34c52
Source
Go
Version published
Created
Source

UPnP in go

Easy for dialog with a UPnP device.

(Sorry if my english is bad in the project or the examples, I try)

I built a tool at https://github.com/micmonay/UpnpTools

This exemple is for get the IPV4 in your router. For exemple your router has duty a UPnP active

up := upnp.NewUPNP(upnp.SERVICE_GATEWAY_IPV4_V2) // or upnp.SERVICE_GATEWAY_IPV4_V1
Interface, err := upnp.GetInterfaceByName("eth0")
if err != nil {
	log.Println(err)
	return
}
// Get all devices compatible for the service name (timeout 1 second)
devices := up.GetAllCompatibleDevice(Interface, 1)
if len(devices) == 0 {
	return
}
// Get services
services := devices[0].GetServicesByType(upnp.SERVICE_GATEWAY_IPV4_V2) // or upnp.SERVICE_GATEWAY_IPV4_V1
if len(services) == 0 {
	return
}
// if you have a one routeur it's ok, other ...
service := services[0]
if service == nil {
	log.Println("not found service")
	return
}
// send request
response, err := service.GetAction("GetExternalIPAddress").Send()
if err != nil {
	log.Println(err)
	return
}
// get response argument
ip, err := response.GetValueArgument("NewExternalIPAddress")
if err != nil {
	log.Println(err)
	return
}
	fmt.Println("Your WAN ip address is " + ip)

If your action containe arguments at sending.

Action := Services[0].GetAction("ActionName")
Action.AddVariable("nameOfArgument","value")
Action.Send()

FAQs

Package last updated on 15 Jun 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.