Giter VIP home page Giter VIP logo

go-external-ip's Introduction

Go External IP Go Workflow Status GoDoc Go Report Cardlicense

A Golang library to get your external ip from multiple services.

TODO

Docs

https://godoc.org/github.com/GlenDC/go-external-ip

Usage

Using the library can as simple as the following (runnable) example:

package main

import (
    "fmt"
    externalip "github.com/glendc/go-external-ip"
)

func main() {
    // Create the default consensus,
    // using the default configuration and no logger.
    consensus := externalip.DefaultConsensus(nil, nil)

    // By default Ipv4 or Ipv6 is returned,
    // use the function below to limit yourself to IPv4,
    // or pass in `6` instead to limit yourself to IPv6.
    // consensus.UseIPProtocol(4)

    // Get your IP,
    // which is never <nil> when err is <nil>.
    ip, err := consensus.ExternalIP()
    if err == nil {
        fmt.Println(ip.String()) // print IPv4/IPv6 in string format
    }
}

Please read the documentation for more information.

exip

This library also comes with a standalone command line application, which can be used to get your external IP, directly from your terminal.

install

$ go install github.com/glendc/go-external-ip/cmd/exip

usage

$ exip -h
Retrieve your external IP.

Usage:
    exip [flags]

Flags:
  -h help
        show this usage message
  -p uint
        IP Protocol to be used (0, 4, or 6)
  -t duration
        consensus's voting timeout (default 5s)
  -v    log errors to STDERR, when defined

go-external-ip's People

Contributors

ductnn avatar glendc avatar gpxlnx avatar jc21 avatar juerd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

go-external-ip's Issues

Change to exclusively use HTTPS providers? (and some suggestions of providers to add)

Problem statement

I wonder if it is a good idea to use only HTTPS providers?
I can't comment much on specific security risks of using non-TLS providers for this purpose (querying external IP), other than the general well-known risks of plaintext communications.
I think the consensus system used in go-external-ip can greatly mitigate MITM attacks, and maybe prevent them completely if at least one provider is using TLS (especially the way go-external-ip is designed to give more weight to TLS providers).

However, on the other hand, is there any real reason to use non-TLS providers when we can change to only HTTPS providers? Is it faster to use HTTP-only providers? (I have not tested, can't see it being that big a difference, especially if we are waiting for multiple providers to get consensus anyway).

All current HTTP-only providers now support HTTPS except:

To make up for removing Akamai, there are others that could be added such as:

(all of these URLs return plain text when requested from non-browser useragent)

Steps to reproduce

N/A

Environment

N/A

Input required from the community and users of this library.

This Library and binary have been written by me, in a long forgotten past. I've noticed however that interest in it never has faded. As a first step I'll go over the project, add CI (testing, quality checks), ensure it works against latest Go versions, and add community guidelines.

I have noticed there are a quite a couple of forks out there. Are any of them active? If so, feel free to be in touch with me to see if we can bring any of your contributions and improvements upstream, so all can benefit from them.

This project had a lot of potential but has never been fully finished. As a community we probably can bring it to a new level. To do this I would like to get some input from the users of this project on what features, improvements and changes you can benefit from. Any suggestions to help shape the roadmap and future direction of this project can help yourself and others.

Kind regards, Glen.

ipv4 and ipv6 addresses

Thanks for the package, I'm using it in my route53-ddns project and it has been flawless forever.

However I've recently added ipv6 support to my home connection and now the external IP returned is the ipv6 address. While this makes sense that the reporting services do this, it would be awesome to be able to get either or both v4 and v6 addresses.

From my quick research, as I understand it the golang resolver will almost simultaneously lookup using v4 and v6 and returns the first one found - but there might be a way to disable one of these protocols.

I'll keep looking but wondered if you know of any other possibilities?

Feature idea: query public IP using DNS (over TLS)

I noticed this repo has a public IP detection package (also Go).

One useful feature I noticed is using DNS protocol itself (actually DNS over TLS) to query public IP from OpenDNS and Cloudflare. (Basically dig +short ANY myip.opendns.com @resolver1.opendns.com).
They are doing it exclusively using DNS over TLS as of this commit. See this issue for explanation of specific attack that is possible using plaintext DNS.

Seems like OpenDNS and Cloudflare are the only two providers that properly support querying public IP over DoT. Google offers a similar service but not over TLS (and was removed in 320d91d for that reason).

Using DNS like this can supposedly be faster and less likely to be rate-limited than HTTP (this is just anecdotal, I haven't verified this). Might be worth adding to the mix as well as STUN.

Also, there is the option to collaborate somehow with qdm12/ddns-updater, e.g. to build a shared external IP library which can be used by that project, or vice versa.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.