Use cymruwhois from pypi and remove submodule
- cymruwhois maintainer recovered his access to pypi and uploaded latest package. There is no need to use it as submodule anymore. So we added an external dependency. - Refactor whois data caching in dnstraceroute and unbreak caching mechanism which was broken since previous commit due to a bug in time delta calculation.
This commit is contained in:
parent
3df692e6db
commit
39e564e626
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -1,3 +0,0 @@
|
|||||||
[submodule "cymruwhois"]
|
|
||||||
path = cymruwhois
|
|
||||||
url = https://github.com/JustinAzoff/python-cymruwhois.git
|
|
@ -1,2 +1 @@
|
|||||||
include LICENSE README.md TODO.md public-servers.txt
|
include LICENSE README.md TODO.md public-servers.txt
|
||||||
include cymruwhois/*.py
|
|
||||||
|
@ -1 +0,0 @@
|
|||||||
Subproject commit a34543335cbef02b1b615e774ce5b6187afb0cc2
|
|
@ -40,7 +40,7 @@ import dns.resolver
|
|||||||
|
|
||||||
__author__ = 'Babak Farrokhi (babak@farrokhi.net)'
|
__author__ = 'Babak Farrokhi (babak@farrokhi.net)'
|
||||||
__license__ = 'BSD'
|
__license__ = 'BSD'
|
||||||
__version__ = "1.6.2"
|
__version__ = "1.6.3"
|
||||||
__progname__ = os.path.basename(sys.argv[0])
|
__progname__ = os.path.basename(sys.argv[0])
|
||||||
shutdown = False
|
shutdown = False
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ import dns.resolver
|
|||||||
|
|
||||||
__author__ = 'Babak Farrokhi (babak@farrokhi.net)'
|
__author__ = 'Babak Farrokhi (babak@farrokhi.net)'
|
||||||
__license__ = 'BSD'
|
__license__ = 'BSD'
|
||||||
__version__ = "1.6.2"
|
__version__ = "1.6.3"
|
||||||
__progname__ = os.path.basename(sys.argv[0])
|
__progname__ = os.path.basename(sys.argv[0])
|
||||||
shutdown = False
|
shutdown = False
|
||||||
|
|
||||||
|
@ -39,13 +39,20 @@ import dns.query
|
|||||||
import dns.rdatatype
|
import dns.rdatatype
|
||||||
import dns.resolver
|
import dns.resolver
|
||||||
|
|
||||||
from cymruwhois import cymruwhois
|
import cymruwhois
|
||||||
|
|
||||||
|
# Global Variables
|
||||||
__author__ = 'Babak Farrokhi (babak@farrokhi.net)'
|
__author__ = 'Babak Farrokhi (babak@farrokhi.net)'
|
||||||
__license__ = 'BSD'
|
__license__ = 'BSD'
|
||||||
__version__ = "1.6.2"
|
__version__ = "1.6.3"
|
||||||
_ttl = None
|
_ttl = None
|
||||||
quiet = False
|
quiet = False
|
||||||
|
whois_cache = {}
|
||||||
|
shutdown = False
|
||||||
|
|
||||||
|
# Constants
|
||||||
|
__progname__ = os.path.basename(sys.argv[0])
|
||||||
|
WHOIS_CACHE = 'whois.cache'
|
||||||
|
|
||||||
|
|
||||||
class CustomSocket(socket.socket):
|
class CustomSocket(socket.socket):
|
||||||
@ -64,11 +71,6 @@ def test_import():
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
# Constants
|
|
||||||
__progname__ = os.path.basename(sys.argv[0])
|
|
||||||
WHOIS_CACHE = 'whois.cache'
|
|
||||||
|
|
||||||
|
|
||||||
class Colors(object):
|
class Colors(object):
|
||||||
N = '\033[m' # native
|
N = '\033[m' # native
|
||||||
R = '\033[31m' # red
|
R = '\033[31m' # red
|
||||||
@ -85,35 +87,41 @@ class Colors(object):
|
|||||||
self.B = ''
|
self.B = ''
|
||||||
|
|
||||||
|
|
||||||
# Globarl Variables
|
def whois_lookup(ip):
|
||||||
shutdown = False
|
|
||||||
|
|
||||||
|
|
||||||
def whoisrecord(ip):
|
|
||||||
try:
|
try:
|
||||||
currenttime = time.perf_counter()
|
global whois_cache
|
||||||
|
currenttime = time.time()
|
||||||
ts = currenttime
|
ts = currenttime
|
||||||
if ip in whois:
|
if ip in whois_cache:
|
||||||
asn, ts = whois[ip]
|
asn, ts = whois_cache[ip]
|
||||||
else:
|
else:
|
||||||
ts = 0
|
ts = 0
|
||||||
if (currenttime - ts) > 36000:
|
if (currenttime - ts) > 36000:
|
||||||
c = cymruwhois.Client()
|
c = cymruwhois.Client()
|
||||||
asn = c.lookup(ip)
|
asn = c.lookup(ip)
|
||||||
whois[ip] = (asn, currenttime)
|
whois_cache[ip] = (asn, currenttime)
|
||||||
return asn
|
return asn
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return e
|
return e
|
||||||
|
|
||||||
|
|
||||||
try:
|
def load_whois_cache(cachefile):
|
||||||
pkl_file = open(WHOIS_CACHE, 'rb')
|
|
||||||
try:
|
try:
|
||||||
whois = pickle.load(pkl_file)
|
pkl_file = open(cachefile, 'rb')
|
||||||
except EOFError:
|
try:
|
||||||
|
whois = pickle.load(pkl_file)
|
||||||
|
pkl_file.close()
|
||||||
|
except Exception:
|
||||||
|
whois = {}
|
||||||
|
except IOError:
|
||||||
whois = {}
|
whois = {}
|
||||||
except IOError:
|
return whois
|
||||||
whois = {}
|
|
||||||
|
|
||||||
|
def save_whois_cache(cachefile, whois_data):
|
||||||
|
pkl_file = open(cachefile, 'wb')
|
||||||
|
pickle.dump(whois_data, pkl_file)
|
||||||
|
pkl_file.close()
|
||||||
|
|
||||||
|
|
||||||
def usage():
|
def usage():
|
||||||
@ -367,11 +375,11 @@ def main():
|
|||||||
if curr_addr:
|
if curr_addr:
|
||||||
as_name = ""
|
as_name = ""
|
||||||
if as_lookup:
|
if as_lookup:
|
||||||
asn = whoisrecord(curr_addr)
|
asn = whois_lookup(curr_addr)
|
||||||
as_name = ''
|
as_name = ''
|
||||||
try:
|
try:
|
||||||
if asn and asn.asn != "NA":
|
if asn and asn.asn != "NA":
|
||||||
as_name = "[%s %s] " % (asn.asn, asn.owner)
|
as_name = "[AS%s %s] " % (asn.asn, asn.owner)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
if shutdown:
|
if shutdown:
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
@ -404,7 +412,7 @@ def main():
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
try:
|
try:
|
||||||
|
whois_cache = load_whois_cache(WHOIS_CACHE)
|
||||||
main()
|
main()
|
||||||
finally:
|
finally:
|
||||||
pkl_file = open(WHOIS_CACHE, 'wb')
|
save_whois_cache(WHOIS_CACHE, whois_cache)
|
||||||
pickle.dump(whois, pkl_file)
|
|
||||||
|
@ -1 +1,2 @@
|
|||||||
dnspython>=1.15.0
|
dnspython>=1.15.0
|
||||||
|
cymruwhois>=1.6
|
||||||
|
4
setup.py
4
setup.py
@ -2,10 +2,10 @@ from setuptools import setup, find_packages
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="dnsdiag",
|
name="dnsdiag",
|
||||||
version="1.6.2",
|
version="1.6.3",
|
||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
scripts=["dnseval.py", "dnsping.py", "dnstraceroute.py"],
|
scripts=["dnseval.py", "dnsping.py", "dnstraceroute.py"],
|
||||||
install_requires=['dnspython>=1.15.0'],
|
install_requires=['dnspython>=1.15.0', 'cymruwhois>=1.6'],
|
||||||
|
|
||||||
classifiers=[
|
classifiers=[
|
||||||
"Topic :: System :: Networking",
|
"Topic :: System :: Networking",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user