Open gwalarn opened 9 years ago
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,
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
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
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'
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
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`
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.