improve whois
This commit is contained in:
		| @ -29,6 +29,7 @@ import concurrent.futures | |||||||
| import getopt | import getopt | ||||||
| import ipaddress | import ipaddress | ||||||
| import os | import os | ||||||
|  | import pickle | ||||||
| import signal | import signal | ||||||
| import socket | import socket | ||||||
| import sys | import sys | ||||||
| @ -36,21 +37,17 @@ import time | |||||||
|  |  | ||||||
| import dns.rdatatype | import dns.rdatatype | ||||||
| import dns.resolver | import dns.resolver | ||||||
|  | from cymruwhois import cymruwhois | ||||||
|  |  | ||||||
| __author__ = 'Babak Farrokhi (babak@farrokhi.net)' | __author__ = 'Babak Farrokhi (babak@farrokhi.net)' | ||||||
| __license__ = 'BSD' | __license__ = 'BSD' | ||||||
| __version__ = 1.3 | __version__ = 1.3 | ||||||
|  |  | ||||||
|  |  | ||||||
| def test_import(): | def test_import(): | ||||||
|  |     #  passing this test means imports were successful | ||||||
|     pass |     pass | ||||||
|  |  | ||||||
| # http://pythonhosted.org/cymruwhois/ |  | ||||||
| try: |  | ||||||
|     import cymruwhois |  | ||||||
|  |  | ||||||
|     has_whois = True |  | ||||||
| except ImportError: |  | ||||||
|     has_whois = False |  | ||||||
|  |  | ||||||
| # Constants | # Constants | ||||||
| __PROGNAME__ = os.path.basename(sys.argv[0]) | __PROGNAME__ = os.path.basename(sys.argv[0]) | ||||||
| @ -76,12 +73,8 @@ class Colors(object): | |||||||
| # Globarl Variables | # Globarl Variables | ||||||
| should_stop = False | should_stop = False | ||||||
|  |  | ||||||
| if has_whois: |  | ||||||
|     from cymruwhois import cymruwhois |  | ||||||
|     import pickle |  | ||||||
|  |  | ||||||
|  | def whoisrecord(ip): | ||||||
|     def whoisrecord(ip): |  | ||||||
|     try: |     try: | ||||||
|         currenttime = time.time() |         currenttime = time.time() | ||||||
|         ts = currenttime |         ts = currenttime | ||||||
| @ -98,13 +91,13 @@ if has_whois: | |||||||
|         return e |         return e | ||||||
|  |  | ||||||
|  |  | ||||||
|     try: | try: | ||||||
|     pkl_file = open(WHOIS_CACHE, 'rb') |     pkl_file = open(WHOIS_CACHE, 'rb') | ||||||
|     try: |     try: | ||||||
|         whois = pickle.load(pkl_file) |         whois = pickle.load(pkl_file) | ||||||
|     except EOFError: |     except EOFError: | ||||||
|         whois = {} |         whois = {} | ||||||
|     except IOError: | except IOError: | ||||||
|     whois = {} |     whois = {} | ||||||
|  |  | ||||||
|  |  | ||||||
| @ -255,10 +248,7 @@ def main(): | |||||||
|         elif o in ("-n"): |         elif o in ("-n"): | ||||||
|             should_resolve = False |             should_resolve = False | ||||||
|         elif o in ("-a", "--asn"): |         elif o in ("-a", "--asn"): | ||||||
|             if has_whois: |  | ||||||
|             as_lookup = True |             as_lookup = True | ||||||
|             else: |  | ||||||
|                 print('Warning: cymruwhois module cannot be loaded. AS Lookup disabled.') |  | ||||||
|         else: |         else: | ||||||
|             usage() |             usage() | ||||||
|  |  | ||||||
| @ -339,7 +329,7 @@ def main(): | |||||||
|  |  | ||||||
|         if curr_addr: |         if curr_addr: | ||||||
|             as_name = "" |             as_name = "" | ||||||
|             if has_whois and as_lookup: |             if as_lookup: | ||||||
|                 ASN = whoisrecord(curr_addr) |                 ASN = whoisrecord(curr_addr) | ||||||
|                 as_name = '' |                 as_name = '' | ||||||
|                 try: |                 try: | ||||||
| @ -379,6 +369,5 @@ if __name__ == '__main__': | |||||||
|     try: |     try: | ||||||
|         main() |         main() | ||||||
|     finally: |     finally: | ||||||
|         if has_whois: |  | ||||||
|         pkl_file = open(WHOIS_CACHE, 'wb') |         pkl_file = open(WHOIS_CACHE, 'wb') | ||||||
|         pickle.dump(whois, pkl_file) |         pickle.dump(whois, pkl_file) | ||||||
|  | |||||||
							
								
								
									
										2
									
								
								setup.py
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								setup.py
									
									
									
									
									
								
							| @ -1,7 +1,7 @@ | |||||||
| from setuptools import setup, find_packages | from setuptools import setup, find_packages | ||||||
| setup( | setup( | ||||||
|     name = "dnsdiag", |     name = "dnsdiag", | ||||||
|     version = "1.3.1", |     version = "1.3.2", | ||||||
| 	packages = find_packages(), | 	packages = find_packages(), | ||||||
|     scripts = ['dnsping.py', 'dnstraceroute.py', 'dnseval.py'], |     scripts = ['dnsping.py', 'dnstraceroute.py', 'dnseval.py'], | ||||||
|     classifiers=[ |     classifiers=[ | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user