proxytools- collection of scripts for harvesting & testing proxies |
git clone git://git.acid.vegas/proxytools.git |
Log | Files | Refs | Archive | README | LICENSE |
torglass.py (3803B)
1 #!/usr/bin/env python 2 # Tor Glass - Developed by acidvegas in Python (https://git.acid.vegas/proxytools) 3 4 ''' 5 A simple script to pull a list of all the Tor relays / exit nodes & generate a json database. 6 7 The example below will generate a map of all the Tor relays / exit nodes using the ipinfo.io API. 8 ''' 9 10 try: 11 import stem.descriptor.remote 12 except ImportError: 13 raise SystemExit('missing required library \'stem\' (https://pypi.org/project/stem/)') 14 15 def get_descriptors() -> dict: 16 ''' Generate a json database of all Tor relays & exit nodes ''' 17 tor_map = {'relay':list(),'exit':list()} 18 for relay in stem.descriptor.remote.get_server_descriptors(): 19 data = { 20 'nickname' : relay.nickname, 21 'fingerprint' : relay.fingerprint, 22 'published' : str(relay.published) if relay.published else None, 23 'address' : relay.address, 24 'or_port' : relay.or_port, 25 'socks_port' : relay.socks_port, 26 'dir_port' : relay.dir_port, 27 'platform' : str(relay.platform) if relay.platform else None, 28 'tor_version' : str(relay.tor_version), 29 'operating_system' : relay.operating_system, 30 'uptime' : relay.uptime, 31 'contact' : str(relay.contact) if relay.contact else None, 32 'exit_policy' : str(relay.exit_policy) if relay.exit_policy else None, 33 'exit_policy_v6' : str(relay.exit_policy_v6) if relay.exit_policy_v6 else None, 34 'bridge_distribution' : relay.bridge_distribution, 35 'family' : list(relay.family) if relay.family else None, 36 'average_bandwidth' : relay.average_bandwidth, 37 'burst_bandwidth' : relay.burst_bandwidth, 38 'observed_bandwidth' : relay.observed_bandwidth, 39 'link_protocols' : relay.link_protocols, 40 'circuit_protocols' : relay.circuit_protocols, 41 'is_hidden_service_dir' : relay.is_hidden_service_dir, 42 'hibernating' : relay.hibernating, 43 'allow_single_hop_exits' : relay.allow_single_hop_exits, 44 'allow_tunneled_dir_requests' : relay.allow_tunneled_dir_requests, 45 'extra_info_cache' : relay.extra_info_cache, 46 'extra_info_digest' : relay.extra_info_digest, 47 'extra_info_sha256_digest' : relay.extra_info_sha256_digest, 48 'eventdns' : relay.eventdns, 49 'ntor_onion_key' : relay.ntor_onion_key, 50 'or_addresses' : relay.or_addresses, 51 'protocols' : relay.protocols 52 } 53 if relay.exit_policy.is_exiting_allowed(): 54 tor_map['exit'].append(data) 55 else: 56 tor_map['relay'].append(data) 57 return tor_map 58 59 60 if __name__ == '__main__': 61 import json 62 63 print('loading Tor descriptors... (this could take a while)') 64 tor_data = get_descriptors() 65 66 with open('tor.json', 'w') as fd: 67 json.dump(tor_data['relay'], fd) 68 with open('tor.exit.json', 'w') as fd: 69 json.dump(tor_data['exit'], fd) 70 71 print('Relays: {0:,}'.format(len(tor_data['relay']))) 72 print('Exits : {0:,}'.format(len(tor_data['exit']))) 73 74 try: 75 import ipinfo 76 except ImportError: 77 raise ImportError('missing optional library \'ipinfo\' (https://pypi.org/project/ipinfo/) for map visualization') 78 79 try: 80 handler = ipinfo.getHandler('changeme') # put your ipinfo.io API key here 81 print('Relay Map: ' + handler.getMap([ip['address'] for ip in tor_data['relay']])) 82 print('Exit Map: ' + handler.getMap([ip['address'] for ip in tor_data['exit']])) 83 except ipinfo.errors.AuthorizationError: 84 print('error: invalid ipinfo.io API key (https://ipinfo.io/signup)') 85 except Exception as ex: 86 print(f'error generating ipinfo map ({ex})')