def main(): initcolor() programmslist = [('dhcp249 ', 'Для рассчета опции 249'), ('gu', 'Для сбора информации о сессии и подключении абонента'), ('n', 'Для генерации сообщения о выдачи IP абоненту'), ('ml', 'Для поиска вендора по мак адресу'), ('h', 'Справка'), ('pipe', 'Для рассчета номера пайпа')] colorlist = [Fore.CYAN, '', Fore.GREEN] print('{} {:<14}{}{}'.format(Fore.YELLOW, 'Скрипт', 'Предназначение', Fore.RESET)) for i, item in enumerate(programmslist): color = colorlist[i % 2] print(f'{color} {item[0]:<14}{item[1]}{Fore.RESET}')
def main(): initcolor() dbfile = 'rt.bisv.bot.db' answ = input( f'Are you sure you want to initiate SQL Lite database: {dbfile}? [Y/n]: ' ) if answ == 'Y' or answ == 'y': print( f'{Fore.YELLOW}ATENTION! Script will erase existing database, and create new form scratch{Fore.RESET}' ) print('You can still stop the process, press Ctrl+C\n') # set timer wait_timer = 5 * 10 # Initial call to print 0% progress printProgressBar(0, wait_timer, prefix='Progress:', suffix='Waiting', length=50, color=Fore.CYAN) for i, item in enumerate(range(0, wait_timer + 1)): # Do stuff... sleep(0.1) # Update Progress Bar printProgressBar(i, wait_timer, prefix='Progress:', suffix='Waiting', length=50, color=Fore.CYAN) print('Start.') if os.path.isfile(dbfile): os.remove(dbfile) print('Database erased.') else: print('Nothing needs to be erased.') initiate(dbfile) print(f'{Fore.YELLOW}Database successfully created.{Fore.RESET}') input('Press any key to exit') else: print('Canceled')
ALL = ["NO_DISPLAY", "NO_DIALOG"] # ------------------------------------------------------------------ # Now we can start loading the API # ------------------------------------------------------------------ # import the core api from . import core from .core import * # noqa: F403, F401, E402 ALL += core.__all__ if not IN_IPYTHON: # needed in Windows terminal - but must not be inited in Jupyter notebook from colorama import init as initcolor initcolor() RUNNING_IN_COLAB = "google.colab" in str(get_ipython()) if IN_IPYTHON and KERNEL and not NO_DISPLAY: # pragma: no cover try: if ( "ipykernel_launcher" in sys.argv[0] and "--InlineBackend.rc={'figure.dpi': 96}" in sys.argv ): # We are running from NBSphinx - the plot must be inline to show up. IP.magic("matplotlib inline") else: if RUNNING_IN_COLAB: # pragma: no cover # allow using matplotlib widget from google.colab import output
#!/usr/bin/env python from colorama import init as initcolor initcolor(autoreset=True) from colorama import Fore, Back def success(txt): print(Back.GREEN + "|Success|", Fore.GREEN + '> ' + txt) def fail(txt): print(Back.RED + "|Failure|", Fore.RED + '> ' + txt) def alert(txt): print(Back.YELLOW + "|Alert|", Fore.YELLOW + '> ' + txt) def note(txt): print(Back.CYAN + "|Note|", Fore.CYAN + '> ' + txt) def greet(txt): print(Back.MAGENTA + "|Greetings|", Fore.MAGENTA + '> ' + txt) def logo(txt): print(Back.WHITE + Fore.BLACK + '|' + txt + '|')
def main(): initcolor() parser = argparse.ArgumentParser(description="Calculates DHCP Option 121/249.", conflict_handler='resolve', \ formatter_class=argparse.RawDescriptionHelpFormatter, \ epilog=f"""Examples:\n %(prog)s wherewasip/21 10.10.10.1 wherewasip/21 10.10.10.1 Output: {CLR.YELLOW}156d.ebb8.0a0a.0a01.159e.3a80.0a0a.0a01{CLR.RESET} %(prog)s -r 156d.ebb8.0a0a.0a01.159e.3a80.0a0a.0a01 Output: {CLR.YELLOW}Subnet Next hop{CLR.RESET} wherewasip/21 10.10.10.1 wherewasip/21 10.10.10.1 %(prog)s -hf /home/xtipacko/routes.txt Output: {CLR.YELLOW}156debb80a0a0a01159e3a800a0a0a01{CLR.RESET}""" ) parser.usage = f"{CLR.GREEN}%(prog)s [[-r] | [-h]] {{ [-f <file>] | <route0... routeN> }}{CLR.RESET}" parser.add_argument('-f', '--file', help="Input filename", metavar="file", type=str) parser.add_argument('--help', help="Show this help message ", action="help") parser.add_argument('routes', help="Routes in format: \"network/mask nexthop\"", nargs="*") # creating and eliminating incompatible options using argparse mode_Reverse_or_Hex = parser.add_mutually_exclusive_group() mode_Reverse_or_Hex.add_argument( '-r', '--reverse', help="Reverse calculation from hex to decimal notation", action='store_true') mode_Reverse_or_Hex.add_argument( '-h', '--hex', help="Output without \".\" splitters, just hex", action='store_true') args = parser.parse_args() # eliminating remaining incompatible options manually if (args.file and args.routes): raise parser.error( "\"-f/--file\" argument is not compatible with \"routes\"") elif (not args.file and not args.routes and args.hex): parser.print_help() sys.exit(0) elif (not args.file and not args.routes): raise parser.error( "You should specify either \"--file\" argument or \"routes\"") # retreiving list of routes if (not args.file and args.routes): routes = " ".join(args.routes) elif (args.file and not args.routes): try: file = open(args.file, "r") routes = "".join(file.readlines()) except: sys.stderr.write("Sorry, can not open file or read list of routes") sys.exit("File reading Error") finally: file.close() #checking options if (not args.hex and not args.reverse): print(Split_ByFour(Hex_ClRoutes(routes))) elif (args.hex and not args.reverse): print(Hex_ClRoutes(routes)) elif (args.reverse and not args.hex): if (routes[:2] == "0x"): hexroutes = routes[2:] hexroutes = re.sub(r'[^0-9a-f]', "", routes) try: listDecRoutes = Dec_ClRoutes(hexroutes) _subnet, _nexthop = "Subnet", "Next hop" print(f"{_subnet:<22}{_nexthop:<19}") colorl = [CLR.CYAN, CLR.GREEN] for i, (subnet, nexthop) in enumerate(listDecRoutes): clr = colorl[i % 2] print("{}{:<22}{:<19}{}".format(clr, subnet, nexthop, CLR.RESET)) except Exception as err: print("Exception: %s" % err)