def _print_storage_row(u, key, title): print_msg('{:>12} | {:>10} | {:>10} ({:>2}%) | {:>10} ({:>2}%)'.format( title, format_bytes(u[key]['total']), format_bytes(u[key]['total'] - u[key]['left']), 100 * (u[key]['total'] - u[key]['left']) / u[key]['total'], format_bytes(u[key]['left']), 100 - 100 * (u[key]['total'] - u[key]['left']) / u[key]['total']))
def _load_sub_names(self): if self.args.full_scan and self.args.file == 'subnames.txt': _file = 'Dict/subnames_full.txt' else: if os.path.exists(self.args.file): _file = self.args.file elif os.path.exists('Dict/%s' % self.args.file): _file = 'Dict/%s' % self.args.file else: print_msg('[ERROR] Names file not found: %s' % self.args.file) exit(-1) normal_lines = [] lines = set() with open(_file) as f: for line in f.xreadlines(): sub = line.strip() if not sub or sub in lines: continue lines.add(sub) normal_lines.append(sub) for item in normal_lines[self.process_num::self.args.process]: self.priority += 1 self.queue.put((self.priority, item))
def print_storage_usage(device): print_msg('{:>12} | {:>10} | {:>16} | {:>10}'.format('Type', 'Total', 'Used', 'Left')) print_msg('{}|{}|{}|{}'.format('-'*13, '-'*12, '-'*18, '-'*17)) u = device.read_storage_usage() _print_storage_row(u, 'trackpoints', 'Trackpoints') _print_storage_row(u, 'logpoints', 'Logpoints') _print_storage_row(u, 'tracklist', 'Tracks') _print_storage_row(u, 'laps', 'Laps')
def print_storage_usage(device): print_msg('{:>12} | {:>10} | {:>16} | {:>10}'.format( 'Type', 'Total', 'Used', 'Left')) print_msg('{}|{}|{}|{}'.format('-' * 13, '-' * 12, '-' * 18, '-' * 17)) u = device.read_storage_usage() _print_storage_row(u, 'trackpoints', 'Trackpoints') _print_storage_row(u, 'logpoints', 'Logpoints') _print_storage_row(u, 'tracklist', 'Tracks') _print_storage_row(u, 'laps', 'Laps')
def _load_sub_names(self): if self.options.full_scan and self.options.file == 'subnames.txt': _file = 'dict/subnames_full.txt' else: if os.path.exists(self.options.file): _file = self.options.file elif os.path.exists('dict/%s' % self.options.file): _file = 'dict/%s' % self.options.file else: print_msg('[ERROR] Names file not found: %s' % self.options.file) exit(-1) normal_lines = [] wildcard_lines = [] wildcard_list = [] regex_list = [] lines = set() with open(_file) as f: for line in f.xreadlines(): sub = line.strip() if not sub or sub in lines: continue lines.add(sub) if sub.find('{alphnum}') >= 0 or sub.find( '{alpha}') >= 0 or sub.find('{num}') >= 0: wildcard_lines.append(sub) sub = sub.replace('{alphnum}', '[a-z0-9]') sub = sub.replace('{alpha}', '[a-z]') sub = sub.replace('{num}', '[0-9]') if sub not in wildcard_list: wildcard_list.append(sub) regex_list.append('^' + sub + '$') else: normal_lines.append(sub) if regex_list: pattern = '|'.join(regex_list) _regex = re.compile(pattern) for line in normal_lines[:]: if _regex.search(line): normal_lines.remove(line) for item in normal_lines[self.process_num::self.options.process]: self.priority += 1 self.queue.put((self.priority, item)) for item in wildcard_lines[self.process_num::self.options.process]: self.queue.put((88888888, item))
def print_history(history, print_storage=False): if not history: print_msg("No tracks") return i = 0 for t in history: if print_storage: u = t.storage_usage print_msg(format(i, '2d'), ':', t.name, ' - Trackpoints ', \ format_bytes(u['trackpoints']), ' - ', \ 'Logpoints', format_bytes(u['logpoints'])) else: print_msg(format(i, '2d'), ':', t.name) i += 1
def upload_strava(tracks, args, fake_garmin_device=False): if args.strava_email is None: print_msg('Missing email for strava.com') return password = args.strava_password if password is None: password = getpass.getpass('Strava.com password:'******'Authenticating to strava.com') uploader.authenticate(args.strava_email, password) except strava.StravaError, e: print_msg('StravaError:', e.reason) return
# # You should have received a copy of the GNU General Public License # along with Bryton-GPS-Linux. If not, see <http://www.gnu.org/licenses/>. # import struct import array import errno import sys from common import print_msg try: import py_sg except ImportError, e: print_msg('You need to install the "py_sg" module.') sys.exit(1) def _scsi_pack_cdb(cmd): return struct.pack('{0}B'.format(len(cmd)), *cmd) def _scsi_read10(addr, block_count, reserved_byte=0): cdb = [0x28, 0, 0, 0, 0, 0, reserved_byte, 0, 0, 0]
def Interface(domain): start_time = time.time() options = AttribDict() options.file = "subnames_full.txt" options.full_scan = False options.i = False options.threads = 100 options.process = 3 options.output = False # make tmp dirs tmp_dir = 'tmp/%s_%s' % (domain, int(time.time())) if not os.path.exists(tmp_dir): os.makedirs(tmp_dir) multiprocessing.freeze_support() all_process = [] dns_servers = load_dns_servers() next_subs = load_next_sub(options) scan_count = multiprocessing.Value('i', 0) found_count = multiprocessing.Value('i', 0) queue_size_list = multiprocessing.Array('i', options.process) try: print '[+] Init %s scan process.' % options.process for process_num in range(options.process): p = multiprocessing.Process( target=run_process, args=(domain, options, process_num, dns_servers, next_subs, scan_count, found_count, queue_size_list, tmp_dir)) all_process.append(p) p.start() while all_process: for p in all_process: if not p.is_alive(): all_process.remove(p) groups_count = 0 for c in queue_size_list: groups_count += c msg = '[*] %s found, %s scanned in %.1f seconds, %s groups left' % ( found_count.value, scan_count.value, time.time() - start_time, groups_count) print_msg(msg) time.sleep(1.0) except KeyboardInterrupt as e: for p in all_process: p.terminate() print '[ERROR] User aborted the scan!' except Exception as e: print e msg = '[+] All Done. %s found, %s scanned in %.1f seconds.' % ( found_count.value, scan_count.value, time.time() - start_time) print_msg(msg, line_feed=True) result = [] for _file in glob.glob(tmp_dir + '/*.txt'): with open(_file, 'r') as tmp_f: content = tmp_f.read() for x in content.strip().split('\n'): try: domain, ips = x.split('\t') for _i in ips.split(','): result.append(_i) except: pass if len(result) == 0: return None return result
Provides an interface to SRTM elevation data stored in GeoTIFF Files. This file is a modified version from the gpxtools project. https://pypi.python.org/pypi/gpxtools """ import sys, random, re, os, urllib2, zipfile, tempfile from math import floor, ceil from cStringIO import StringIO from common import print_msg try: from osgeo import gdal, gdalnumeric except ImportError: print_msg('You need the GDAL library (https://pypi.python.org/pypi/GDAL/) ' \ 'to use the elevation database.') sys.exit(1) from brytongps import format_bytes DOWNLOAD_URL = 'http://droppr.org/srtm/v4.1/6_5x5_TIFs/%s.zip' def bilinear_interpolation(tl, tr, bl, br, a, b): """ Based on equation from: http://en.wikipedia.org/wiki/Bilinear_interpolation :Parameters: tl : int top-left
def sb_main(args, domain): start_time = time.time() html_host_str = '' html_general = Template(TempleteHtml_sub.html['general']) tmp_dir = 'tmp/%s_%s' % (domain, int(time.time())) if not os.path.exists(tmp_dir): os.makedirs(tmp_dir) multiprocessing.freeze_support() all_process = [] dns_servers = load_dns_servers() next_subs = load_next_sub(args) scan_count = multiprocessing.Value('i', 0) found_count = multiprocessing.Value('i', 0) queue_size_list = multiprocessing.Array('i', args.process) try: print '[+] Init %s scan process.' % args.process for process_num in range(args.process): p = multiprocessing.Process( target=run_process, args=(domain, args, process_num, dns_servers, next_subs, scan_count, found_count, queue_size_list, tmp_dir)) all_process.append(p) p.start() while all_process: for p in all_process: if not p.is_alive(): all_process.remove(p) groups_count = 0 for c in queue_size_list: groups_count += c msg = '[*] %s found, %s scanned in %.1f seconds, %s groups left' % ( found_count.value, scan_count.value, time.time() - start_time, groups_count) print_msg(msg) time.sleep(1.0) except KeyboardInterrupt as e: for p in all_process: p.terminate() print '[ERROR] User aborted the scan!' sys.exit(0) except Exception as e: print e msg = '[+] SubBrute Done. %s found, %s scanned in %.1f seconds.' % ( found_count.value, scan_count.value, time.time() - start_time) print_msg(msg, line_feed=True) out_file_name = get_out_file_name_txt(domain, args) with open(out_file_name, 'w') as f: for _file in glob.glob(tmp_dir + '/*.txt'): with open(_file, 'r') as tmp_f: content = tmp_f.read() f.write(content) print '[Attention] The sub blasting result is saved in %s' % out_file_name out_file_name = get_out_file_name_html(domain, args) with open(out_file_name, 'w+') as f: for _file in glob.glob('tmp' + '/*.txt'): with open(_file, 'r') as tmp_f: html_host_str += tmp_f.read() f.write(html_general.substitute(content1=html_host_str)) print '[Attention] The sub blasting result is saved in %s' % out_file_name
def print_summary(s, track=None, print_storage=False): ts = datetime.datetime.fromtimestamp print_msg('===================================================') print_msg(ts(s.start)) print_msg('{0} - {1} ({2})'.format(ts(s.start), ts(s.end), datetime.timedelta(seconds=s.ride_time))) print_msg(' Dist: {0:.2f}Km'.format(s.distance / 1000.0)) print_msg(' Cal: {0}'.format(s.calories)) print_msg(' Alt: {0}m / {1}m (gain/loss)'.format(s.altitude_gain, s.altitude_loss)) print_msg(' Speed: {0}Kph / {1}Kph (avg/max)'.format(s.speed.avg, s.speed.max)) if s.heartrate is not None and s.heartrate.max > 0: print_msg(' Hr: {0}bpm / {1}bpm (avg/max)'.format(s.heartrate.avg, s.heartrate.max)) if s.cadence is not None and s.cadence.max > 0: print_msg(' Cad: {0}rpm / {1}rpm (avg/max)'.format(s.cadence.avg, s.cadence.max)) if s.watts is not None and s.watts.max > 0: print_msg(' Watts: {0}/{1} (avg/max)'.format(s.watts.avg, s.watts.max)) if track is not None and track.lap_count > 0: print_msg(' Laps: {0}'.format(len(track.lap_summaries))) if print_storage: u = track.storage_usage print_msg('Storage: Trackpoints', \ format_bytes(u['trackpoints']), ' - ', \ 'Logpoints', format_bytes(u['logpoints']))
uploader = strava.StravaUploader(fake_garmin_device=fake_garmin_device, no_laps=args.no_laps) try: print_msg('Authenticating to strava.com') uploader.authenticate(args.strava_email, password) except strava.StravaError, e: print_msg('StravaError:', e.reason) return for t in tracks: try: print_msg('Uploading track: {0}'.format(t.name)) upload = uploader.upload(t) while not upload.finished: time.sleep(3) p = upload.check_progress() print_msg('Uploaded OK') except strava.StravaError, e: print_msg('StravaError:', e.reason)
password = getpass.getpass('Strava.com password:'******'Authenticating to strava.com') uploader.authenticate(args.strava_email, password) except strava.StravaError, e: print_msg('StravaError:', e.reason) return for t in tracks: try: print_msg('Uploading track: {0}'.format(t.name)) upload = uploader.upload(t) while not upload.finished: time.sleep(3) p = upload.check_progress() print_msg('Uploaded OK') except strava.StravaError, e: print_msg('StravaError:', e.reason) def options(): p = argparse.ArgumentParser(description='Bryton GPS Linux')
# # You should have received a copy of the GNU General Public License # along with Bryton-GPS-Linux. If not, see <http://www.gnu.org/licenses/>. # import struct import array import errno import sys from common import print_msg try: import py_sg except ImportError, e: print_msg('You need to install the "py_sg" module.') sys.exit(1) def _scsi_pack_cdb(cmd): return struct.pack('{0}B'.format(len(cmd)), *cmd) def _scsi_read10(addr, block_count, reserved_byte=0): cdb = [0x28, 0, 0, 0, 0, 0, reserved_byte, 0, 0, 0] a = struct.pack('>I', addr) cdb[2] = ord(a[0]) cdb[3] = ord(a[1])
def print_summary(s, track=None, print_storage=False): ts = datetime.datetime.fromtimestamp print_msg('===================================================') print_msg(ts(s.start)) print_msg('{0} - {1} ({2})'.format(ts(s.start), ts( s.end), datetime.timedelta(seconds=s.ride_time))) print_msg(' Dist: {0:.2f}Km'.format(s.distance / 1000.0)) print_msg(' Cal: {0}'.format(s.calories)) print_msg(' Alt: {0}m / {1}m (gain/loss)'.format( s.altitude_gain, s.altitude_loss)) print_msg(' Speed: {0}Kph / {1}Kph (avg/max)'.format( s.speed.avg, s.speed.max)) if s.heartrate is not None and s.heartrate.max > 0: print_msg(' Hr: {0}bpm / {1}bpm (avg/max)'.format( s.heartrate.avg, s.heartrate.max)) if s.cadence is not None and s.cadence.max > 0: print_msg(' Cad: {0}rpm / {1}rpm (avg/max)'.format( s.cadence.avg, s.cadence.max)) if s.watts is not None and s.watts.max > 0: print_msg(' Watts: {0}/{1} (avg/max)'.format(s.watts.avg, s.watts.max)) if track is not None and track.lap_count > 0: print_msg(' Laps: {0}'.format(len(track.lap_summaries))) if print_storage: u = track.storage_usage print_msg('Storage: Trackpoints', \ format_bytes(u['trackpoints']), ' - ', \ 'Logpoints', format_bytes(u['logpoints']))