Permalink
Browse files

Support DNS LOC record for @<domain> queries

Query LOC record first; use IP address as fallback.
  • Loading branch information...
sehaas committed Jul 26, 2017
1 parent 2110642 commit 6e5efdeb5e5068626422cf9a613fae920ac47e02
Showing with 9 additions and 1 deletion.
  1. +8 −1 bin/srv.py
  2. +1 −0 requirements.txt
@@ -14,6 +14,9 @@
from gevent.subprocess import Popen, PIPE
patch_all()
import dns.resolver
from dns.exception import DNSException
from flask import Flask, request, render_template, send_from_directory
app = Flask(__name__)
@@ -257,7 +260,11 @@ def wttr(location = None):
if is_ip( location ):
location = get_location( location )
if location.startswith('@'):
location = get_location( socket.gethostbyname( location[1:] ) )
try:
loc = dns.resolver.query( location[1:], 'LOC' )
location = str("%.7f,%.7f" % (loc[0].float_latitude, loc[0].float_longitude))
except DNSException, e:
location = get_location( socket.gethostbyname( location[1:] ) )
location = location_canonical_name( location )
log("%s %s %s %s" % (ip, user_agent, orig_location, location))
@@ -3,3 +3,4 @@ geoip2
geopy
requests
gevent
dnspython

0 comments on commit 6e5efde

Please sign in to comment.