inetaddr

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2021 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

inetaddr

Goal

inetaddr is a tool that allows get external IP address simply, faster and securely:

  • allows get IP address from many DNS servers
  • allows get IP address from many HTTP servers
Install
go get github.com/basti0nz/inetaddr
Example

package main

import (
	"fmt"
	"github.com/basti0nz/inetaddr"
)

const (
	OnlyDNS = iota
	OnlyHTTP
	BothMethod
)

func main() {
	ip, err := inetaddr.IpAddrString(OnlyDNS)
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(ip)

	ipIP, err := inetaddr.IpAddrIP(OnlyHTTP)
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(ipIP.String())

	ip, err = inetaddr.IpAddrString(BothMethod)
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(ip)
}

TODO:

  • use proxy

License

MIT

Issues

Please open issues here: New Issue

Suggestions and improvements are welcome.

-Valentyn Nastenko(c 2021) https://github.com/versus

Documentation

Index

Constants

View Source
const (
	OnlyDNS = iota
	OnlyHTTP
	BothMethod
)

Variables

View Source
var DnsServerS = []DnsServer{
	{"resolver3.opendns.com", "myip.opendns.com", dns.TypeA},
	{"resolver4.opendns.com", "myip.opendns.com", dns.TypeA},
	{"resolver2.opendns.com", "myip.opendns.com", dns.TypeA},
	{"resolver1.opendns.com", "myip.opendns.com", dns.TypeA},
	{"ns1-1.akamaitech.net", "whoami.akamai.net", dns.TypeA},
	{"za.akamaitech.net", "whoami.akamai.net", dns.TypeA},
	{"zb.akamaitech.net", "whoami.akamai.net", dns.TypeA},
	{"zc.akamaitech.net", "whoami.akamai.net", dns.TypeA},
	{"zd.akamaitech.net", "whoami.akamai.net", dns.TypeA},
	{"ns1.google.com", "o-o.myaddr.l.google.com", dns.TypeTXT},
	{"ns2.google.com", "o-o.myaddr.l.google.com", dns.TypeTXT},
	{"ns3.google.com", "o-o.myaddr.l.google.com", dns.TypeTXT},
}
View Source
var HttpServerS = []HttpServer{
	{"https://ifconfig.me/"},
	{"https://icanhazip.com/"},
	{"https://ident.me/"},
	{"https://ipecho.net/plain"},
	{"https://checkip.amazonaws.com/"},
	{"https://wgetip.com/"},
	{"https://ip.tyk.nu/"},
	{"https://bot.whatismyipaddress.com/"},
	{"https://ipof.in/txt"},
	{"https://l2.io/ip"},
	{"https://eth0.me/"},
}

Functions

func DnsCheck

func DnsCheck(record DnsServer) (net.IP, error)

func HttpCheck

func HttpCheck(r HttpServer) (net.IP, error)

func InetAddr

func InetAddr(flagCheckType int) string

func IpAddrIP

func IpAddrIP(flagCheckType int) (net.IP, error)

func IpAddrString

func IpAddrString(flagCheckType int) (string, error)

Types

type DnsServer

type DnsServer struct {
	Server     string
	Record     string
	RecordType dns.QueryType
}

type HttpServer

type HttpServer struct {
	Server string
}

type IPAddrResolver

type IPAddrResolver interface {
	IpAddrString() (string, error)
	IpAddrIP() (net.IP, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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