extip

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2023 License: MIT Imports: 3 Imported by: 1

README

extip

Go package which retrieves external IP address using STUN servers


❤ ❤ ❤

You can say thanks to the author by donations to these wallets:

  • ETH: 0xB71250010e8beC90C5f9ddF408251eBA9dD7320e
  • BTC:
    • Legacy: 1N89PRvG1CSsUk9sxKwBwudN6TjTPQ1N8a
    • Segwit: bc1qc0hcyxc000qf0ketv4r44ld7dlgmmu73rtlntw

Usage

Example:

package main

import (
    "fmt"
    "github.com/Snawoot/extip"
    "context"
    "os"
    "time"
)

func main() {
    ctx, _ := context.WithTimeout(context.Background(), 3 * time.Second)
    ip, err := extip.QueryMultipleServers(ctx, nil, 2, false)
    if err != nil {
        switch res := err.(type) {
        case extip.InconclusiveResult:
            fmt.Fprintf(os.Stderr, "Inconclusive result:\n")
            fmt.Fprintf(os.Stderr, "Required quorum = %v\n", res.Quorum)
            for k, v := range res.Results {
                fmt.Fprintf(os.Stderr, "Server %s responded: %s\n", k, v)
            }
            for k, v := range res.Errors {
                fmt.Fprintf(os.Stderr, "Server %s failed: %v\n", k, v)
            }
        default:
            fmt.Fprintf(os.Stderr, "Error: %v\n", err)
        }
        return
    }
    fmt.Println(ip)
}

See GoDoc and sources for more details.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PublicServerList = []string{
	"stun.l.google.com:19302",
	"stun.ekiga.net:3478",
	"stun.schlund.de:3478",
	"stun.voiparound.com:3478",
	"stun.voipbuster.com:3478",
	"stun.voipstunt.com:3478",
}

Functions

func QueryMultipleServers

func QueryMultipleServers(ctx context.Context, servers []string, quorum uint, ipv6 bool) (string, error)

Query multiple servers and determine result by quorum of successful responses. List of servers can be a nil slice. In this case public server list will be used. Recommended quorum value is 2.

func QuerySingleServer

func QuerySingleServer(ctx context.Context, server string, ipv6 bool) (string, error)

Query external IP address from single server

Types

type InconclusiveResult

type InconclusiveResult struct {
	// Map with error for each failed server
	Errors map[string]error

	// Map with result for each server
	Results map[string]string

	// Quorum set for matching responses
	Quorum uint
}

func (InconclusiveResult) Error

func (_ InconclusiveResult) Error() string

Jump to

Keyboard shortcuts

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