Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

retrieve actual IP address via dns #15

Open
gwalarn opened this issue Feb 7, 2015 · 6 comments
Open

retrieve actual IP address via dns #15

gwalarn opened this issue Feb 7, 2015 · 6 comments

Comments

@gwalarn
Copy link

gwalarn commented Feb 7, 2015

We can retriev our actual IP via:
dig +short myip.opendns.com @resolver1.opendns.com

It's easier, faster and more sure than a web site.

@Chralu
Copy link
Owner

Chralu commented Dec 30, 2015

Hi @gwalarn,

you're right about this, moreover I just tried the command you gave, it fails on a "connection timed out".
Maybe is it because of my working place network.

anyway thanks for the tip, I'll try to investigate.

Cheers,

@gwalarn
Copy link
Author

gwalarn commented Dec 30, 2015

Hi,
If a timeout occurs when accessing to opendns dns servers, maybe you do the query from a machine connected to an ISP which prohibits dns queries to other servers than those of your ISP? Can you verify that you can join the Google servers for example with:
dig +short github.com @8.8.8.8
and try the query from an other ISP to confirm the obligation to use a "serveur DNS menteur" that don't respect the net neutrality.

Cheers

@tintamarre
Copy link

Something like that ?

import dns.resolver # $ pip install dnspython

resolver = dns.resolver.Resolver(configure=False)
resolver.nameservers = ["208.67.222.222", "208.67.220.220"]
public_ip = resolver.query('myip.opendns.com')[0]
return public_ip

@gwalarn
Copy link
Author

gwalarn commented Feb 8, 2016

Thanks for the programming example, I never program in python but when i do a comparison of public_ip (result of resolver.query('myip.opendns.com')[0] and a string containing my IP like this:

current_ip_address = "1.1.1.1" # remplace 1.1.1.1 with my real IP
resolver = dns.resolver.Resolver(configure=False)
resolver.nameservers = ["208.67.222.222", "208.67.220.220"]
public_ip = resolver.query('myip.opendns.com')[0]
if current_ip_address != previous_ip_address:
print('KO')
else:
print('OK')

the result is "KO"

Are the variable typed in python?
when i write:
public_ip = str(resolver.query('myip.opendns.com')[0])
the comparison is OK

PS: If we prefer use google than opendns our public IP can be obtain with this dns request:
dig TXT +short o-o.myaddr.l.google.com @ns1.google.com | sed 's/"//g'

@ghost
Copy link

ghost commented Mar 5, 2017

Hi,
I added a new IP provider because I wasn't able to get IP from the two previous ones.

My updates in adapter.py :

class IPYunohost( object ):
  def get_public_ip( self ):
    """Returns the current public IP address. Raises an exception if an issue occurs."""
    try:
      url_page = 'http://ip.yunohost.org'
      public_ip = None

      f = urllib.request.urlopen(url_page)
      data = f.read().decode("utf8")
      f.close()
      pattern = re.compile('\d+\.\d+\.\d+\.\d+')
      result = pattern.search(data, 0)
      if result == None:
        raise ipretriever.Fault('Service '+url_page+' failed to return the current public IP address')
      else:
        public_ip = result.group(0)
    except urllib.error.URLError as e:
      raise ipretriever.Fault(e)
    return public_ip

and in gandyn.py line 141 :

public_ip_retriever = ipretriever.adapter.IPYunohost()

Best regards

@tintamarre
Copy link

This is what I currently use : https://gist.github.com/tintamarre/067fbf48bee4081fc46348d11f10625a

I got Public IP from this command :

public_ip=`dig +short myip.opendns.com @resolver1.opendns.com` 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants