nat

package module
v0.0.0-...-f763572 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2019 License: GPL-3.0 Imports: 4 Imported by: 1

README

NAT library for Golang

This library is for NAT port mapping only!

  • Currently Support UPnP for IGD v1 & v2
  • Support NAT-PMP (by plan)
  • Support DMZ (by plan)

Installation

Run go get https://github.com/symphonyprotocol/nat

Usage

  1. UPnP port mapping
package main

import (
	"fmt"
	"github.com/symphonyprotocol/nat"
	"github.com/symphonyprotocol/nat/upnp"
)

func main() {
	ips, _ := nat.IntranetIP()
	fmt.Println(ips)
	client, _ := upnp.NewUPnPClient()
	if ok := client.Discover(); ok {
		ip, _ := upnp.GetExternalIPAddress(client)
		fmt.Println(ip)
		if ok := upnp.AddPortMapping(ips[0], 1234, 1234, "UDP", client); ok {
			fmt.Println("add UDP success")
		}
		if ok := upnp.AddPortMapping(ips[0], 1234, 1234, "TCP", client); ok {
			fmt.Println("add UDP success")
		}
		if ok := upnp.DeletePortMapping(1234, "UDP", client); ok {
			fmt.Println("delete success")
		}
	}

}

module support

  • In progress

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetOutbountIP

func GetOutbountIP() (string, error)

func IntranetIP

func IntranetIP() (ips []string, err error)

func IsIntranet

func IsIntranet(ipStr string) bool

Types

This section is empty.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL