Skip to content

ppma/nat-type

Repository files navigation

MIT licensed

介绍

nat-typeRFC 3489 的go实现,从 NatTypeDetector 移植而来。 代码写得烂,思想跟不上,就这样了

使用

package main

import (
	"fmt"
	"github.com/ppma/nat-type"
)

const (
	STUN_SERVER = "stun.miwifi.com"
	STUN_PORT   = 3478
)

func main() {
	localAddr := fmt.Sprintf("%s:%d", "192.168.101.3", STUN_PORT)
	stunAddr := fmt.Sprintf("%s:%d", STUN_SERVER, STUN_PORT)
	result, err := stun.Query(stunAddr, localAddr)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println("Nat type: ", result.GetNatType())
	fmt.Println("Public IP: ", result.GetIpAddr())
}

About

探测Nat类型

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages