From be7825d9834370f18cc42c7d8f1e9f85e4d7518c Mon Sep 17 00:00:00 2001 From: Vadim Yanitskiy Date: Sun, 19 Nov 2017 17:16:24 +0700 Subject: fake_trx/ctrl_cmd.py: add help and basic command line options Sometimes it's important to use different CTRL port, for example when OsmoTRX is running at the same time. This change adds the corresponding command line options and help message. Change-Id: Ic6eeb69d9a1fc151eab2e63f3708e3d70e2e558b --- src/target/fake_trx/ctrl_cmd.py | 61 +++++++++++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 8 deletions(-) (limited to 'src/target') diff --git a/src/target/fake_trx/ctrl_cmd.py b/src/target/fake_trx/ctrl_cmd.py index 30b19bdc..b7aec50b 100755 --- a/src/target/fake_trx/ctrl_cmd.py +++ b/src/target/fake_trx/ctrl_cmd.py @@ -23,6 +23,7 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import signal +import getopt import select import sys @@ -36,18 +37,62 @@ COPYRIGHT = \ "There is NO WARRANTY, to the extent permitted by law.\n" class Application: - def __init__(self, remote_addr, remote_port, bind_port, fuz = False): - # Init UDP connection - self.ctrl_link = UDPLink(remote_addr, remote_port, bind_port) + # Application variables + remote_addr = "127.0.0.1" + base_port = 5700 + fuzzing = False - # Determine working mode - self.fuzzing = fuz + def __init__(self): + print(COPYRIGHT) + self.parse_argv() # Set up signal handlers signal.signal(signal.SIGINT, self.sig_handler) - # Print copyright - print(COPYRIGHT) + # Init UDP connection + self.ctrl_link = UDPLink(self.remote_addr, + self.base_port + 1, self.base_port + 101) + + def print_help(self, msg = None): + s = " Usage: " + sys.argv[0] + " [options]\n\n" \ + " Some help...\n" \ + " -h --help this text\n\n" + + s += " TRX interface specific\n" \ + " -r --remote-addr Set remote address (default %s)\n" \ + " -p --base-port Set base port number (default %d)\n" \ + " -f --fuzzing Send raw payloads (without CMD)\n" \ + + print(s % (self.remote_addr, self.base_port)) + + if msg is not None: + print(msg) + + def parse_argv(self): + try: + opts, args = getopt.getopt(sys.argv[1:], + "r:p:fh", + [ + "help", + "fuzzing", + "base-port=", + "remote-addr=", + ]) + except getopt.GetoptError as err: + self.print_help("[!] " + str(err)) + sys.exit(2) + + for o, v in opts: + if o in ("-h", "--help"): + self.print_help() + sys.exit(2) + + elif o in ("-r", "--remote-addr"): + self.remote_addr = v + elif o in ("-p", "--base-port"): + self.base_port = int(v) + elif o in ("-f", "--fuzzing"): + self.fuzzing = True def run(self): while True: @@ -88,5 +133,5 @@ class Application: sys.exit(0) if __name__ == '__main__': - app = Application("127.0.0.1", 5701, 5801) + app = Application() app.run() -- cgit v1.2.3