def init_argparse(cls): parser = PupyArgumentParser(prog='rfs', description=cls.__doc__) commands = parser.add_subparsers(dest='command') mount = commands.add_parser('mount') mount.add_argument('src', help='Remote directory') mount.add_argument('dest', help='Local mount point') mount.set_defaults(func=cls.mount) umount = commands.add_parser('umount') umount.add_argument('dest', help='Local mount point') umount.set_defaults(func=cls.umount) mlist = commands.add_parser('list') mlist.set_defaults(func=cls.list) cls.arg_parser = parser
from pupylib.PupyOutput import Success, Error, Table, Color import time usage = 'DNSCNC control' parser = PupyArgumentParser(prog='dnscnc', description=usage) parser.add_argument('-n', '--node', help='Send command only to this node (or session)') parser.add_argument('-d', '--default', action='store_true', default=False, help='Set command as default for new connections') commands = parser.add_subparsers(title='commands', dest='command') status = commands.add_parser('status', help='DNSCNC status') sessions = commands.add_parser('sessions', help='List known DNSCNC sessions') sessions.add_argument('-r', action='store_true', help='Reverse sorting') sorting = sessions.add_mutually_exclusive_group() sorting.add_argument('-b', action='store_true', help='Sort by boot time') sorting.add_argument('-o', action='store_true', help='Sort by OS') sorting.add_argument('-i', action='store_true', help='Sort by IP') sorting.add_argument('-n', action='store_true', help='Sort by node') sorting.add_argument('-d', action='store_true', help='Sort by duration') sorting.add_argument('-c', action='store_true', help='Sort by pending commands') nodes = commands.add_parser('nodes', help='List known DNSCNC nodes')
def init_argparse(cls): cli = IGDCMDClient() parser = PupyArgumentParser(prog='igdc', description=cls.__doc__) parser.add_argument('-d', '--DEBUG', action='store_true', help='enable DEBUG output') parser.add_argument( '-pp', '--pretty_print', action='store_true', help='enable xml pretty output for debug and custom action') parser.add_argument('-s', '--source', default='0.0.0.0', help='source address of requests') parser.add_argument('-u', '--url', help='control URL') subparsers = parser.add_subparsers() parser_start = subparsers.add_parser('add', help='add port mapping') parser_start.add_argument('intPort', type=int, help='Internal Port') parser_start.add_argument('extPort', type=int, help='External Port') parser_start.add_argument('proto', choices=['UDP', 'TCP'], help='Protocol') parser_start.add_argument('intIP', nargs='?', default=None, help='Internal IP') parser_start.add_argument('-r', '--remote', default='', help='remote host') parser_start.add_argument('-d', '--desc', default='', help='Description of port mapping') parser_start.add_argument('-e', '--enabled', type=int, choices=[1, 0], default=1, help='enable or disable port mapping') parser_start.add_argument('-du', '--duration', type=int, default=0, help='Duration of the mapping') parser_start.set_defaults(func=cli.addPM) parser_del = subparsers.add_parser('del', help='del port mapping') parser_del.add_argument('extPort', type=int, help='External Port') parser_del.add_argument('proto', choices=['UDP', 'TCP'], help='Protocol') parser_del.add_argument('-r', '--remote', default='', help='remote host') parser_del.set_defaults(func=cli.delPM) parser_geip = subparsers.add_parser('getextip', help='get external IP') parser_geip.set_defaults(func=cli.getExtIP) parser_gpm = subparsers.add_parser('getgpm', help='get generic pm entry') parser_gpm.add_argument('-i', '--index', type=int, help='index of PM entry') parser_gpm.set_defaults(func=cli.getGPM) parser_spm = subparsers.add_parser('getspm', help='get specific port mapping') parser_spm.add_argument('extPort', type=int, help='External Port') parser_spm.add_argument('proto', choices=['UDP', 'TCP'], help='Protocol') parser_spm.add_argument('-r', '--remote', default='', help='remote host') parser_spm.set_defaults(func=cli.getSPM) parser_nrss = subparsers.add_parser('getnrss', help='get NAT and RSIP status') parser_nrss.set_defaults(func=cli.getNRSS) parser_gwdd = subparsers.add_parser('getwdd', help='get warn disconnect delay') parser_gwdd.set_defaults(func=cli.getWDD) parser_swdd = subparsers.add_parser('setwdd', help='set warn disconnect delay') parser_swdd.add_argument('delay', type=int, help='warn disconnect delay') parser_swdd.set_defaults(func=cli.setWDD) parser_gidt = subparsers.add_parser('getidt', help='get idle disconnect time') parser_gidt.set_defaults(func=cli.getIDT) parser_sidt = subparsers.add_parser('setidt', help='set idle disconnect time') parser_sidt.add_argument('time', type=int, help='idle disconnect time') parser_sidt.set_defaults(func=cli.setIDT) parser_gadt = subparsers.add_parser('getadt', help='get auto disconnect time') parser_gadt.set_defaults(func=cli.getADT) parser_sadt = subparsers.add_parser('setadt', help='set auto disconnect time') parser_sadt.add_argument('time', type=int, help='auto disconnect time') parser_sadt.set_defaults(func=cli.setADT) parser_gsi = subparsers.add_parser('getsi', help='get status info') parser_gsi.set_defaults(func=cli.getSI) parser_rt = subparsers.add_parser('rt', help='request termination') parser_rt.set_defaults(func=cli.requestTerm) parser_ft = subparsers.add_parser('ft', help='force termination') parser_ft.set_defaults(func=cli.forceTerm) parser_rc = subparsers.add_parser('rc', help='request connection') parser_rc.set_defaults(func=cli.requestConn) parser_gct = subparsers.add_parser('getct', help='get connection type info') parser_gct.set_defaults(func=cli.getCT) parser_sct = subparsers.add_parser('setct', help='set connection type') parser_sct.add_argument('ct_type', help='connection type') parser_sct.set_defaults(func=cli.setCT) parser_cust = subparsers.add_parser('custom', help='use custom action') parser_cust.add_argument('method_name', help='name of custom action') parser_cust.add_argument( '-svc', type=str, choices=['WANIPConnection', 'WANIPv6FirewallControl'], default='WANIPConnection', help='IGD service, default is WANIPConnection') parser_cust.add_argument( '-iargs', '--input_args', default='{}', help='input args, the format is same as python dict,' 'e.g. "{\'NewPortMappingIndex\': [0, \'ui4\']}"') parser_cust.set_defaults(func=cli.custom) # following for IPv6FWControl parser_gfwstatus = subparsers.add_parser('getfwstatus', help='get IPv6 FW status') parser_gfwstatus.set_defaults(func=cli.getFWStatus) parser_addph = subparsers.add_parser('addph', help='add IPv6 FW Pinhole') parser_addph.add_argument('intIP', help='Internal IP') parser_addph.add_argument('-intPort', type=int, default=0, help='Internal Port') parser_addph.add_argument('proto', choices=['UDP', 'TCP', 'ALL'], help='Protocol') parser_addph.add_argument('-rIP', default='', help='Remote IP') parser_addph.add_argument('-rPort', type=int, default=0, help='Remote Port') parser_addph.add_argument('-lease', type=int, default=3600, help='leasetime of the pinhole') parser_addph.set_defaults(func=cli.addPH) parser_gopht = subparsers.add_parser( 'getopht', help='get IPv6 FW OutboundPinholeTimeout') parser_gopht.add_argument('-intIP', type=str, default='', help='Internal IP') parser_gopht.add_argument('-intPort', type=int, default=0, help='Internal Port') parser_gopht.add_argument('-proto', choices=['UDP', 'TCP', 'ALL'], default='ALL', help='Protocol') parser_gopht.add_argument('-rIP', default='', help='Remote IP') parser_gopht.add_argument('-rPort', type=int, default=0, help='Remote Port') parser_gopht.set_defaults(func=cli.getOPHT) parser_uph = subparsers.add_parser('updateph', help='update IPv6 FW pinhole') parser_uph.add_argument('uid', type=int, help='UniqueID of the pinhole') parser_uph.add_argument('lease', type=int, help='new leasetime of the pinhole') parser_uph.set_defaults(func=cli.updatePH) parser_dph = subparsers.add_parser('delph', help='delete IPv6 FW pinhole') parser_dph.add_argument('uid', type=int, help='UniqueID of the pinhole') parser_dph.set_defaults(func=cli.delPH) parser_gphpkts = subparsers.add_parser( 'getphpkts', help='get number of packets go through specified IPv6FW pinhole') parser_gphpkts.add_argument('uid', type=int, help='UniqueID of the pinhole') parser_gphpkts.set_defaults(func=cli.getPHPkts) parser_chkph = subparsers.add_parser( 'chkph', help='check if the specified pinhole is working') parser_chkph.add_argument('uid', type=int, help='UniqueID of the pinhole') parser_chkph.set_defaults(func=cli.chkPH) cls.arg_parser = parser cls.cli = cli