Skip to content

Latest commit

 

History

History
executable file
·
59 lines (42 loc) · 1.05 KB

Readme.md

File metadata and controls

executable file
·
59 lines (42 loc) · 1.05 KB

Package extip is external IPv4 or IPv6 address check

GoDev Go

DESCRIPTION

extip returns the public facing IPv4 or IPv6 address of the requesting client by querying servers at STUN

usage

$ go get github.com/skubota/extip

package extip

https://pkg.go.dev/github.com/skubota/extip

package main

import (
	"fmt"
	"github.com/skubota/extip"
)

func main() {
	// Any
	addr,err := extip.GetIP()
	if err != nil {
		fmt.Errorf("Address cannot get : %s\n", err)
	}else{
		fmt.Printf("Adress : %s\n",addr) 
	}


	// IPv4
	ipv4,err := extip.GetIP4()
	if err != nil {
		fmt.Errorf("IPv4 address cannot get : %s\n", err)
	}else{
		fmt.Printf("IPv4 address : %s\n", ipv4)
	}

	// IPv6
	ipv6,err := extip.GetIP6()
	if err != nil {
		fmt.Errorf("IPv6 address cannot get : %s\n", err)
	}else{
		fmt.Printf("IPv6 address : %s\n", ipv6)
	}
}