summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVadim Yanitskiy <axilirator@gmail.com>2018-03-06 22:50:36 +0700
committerVadim Yanitskiy <axilirator@gmail.com>2018-03-06 22:54:21 +0700
commit7fd8ef2d3f3d296a6032745396d3af8e8e3d4da2 (patch)
treed03f8fc9e59e844f0d56630c7811b7a18882a6aa
parent2812cb7f80e08205f831934886c6019c92947614 (diff)
fake_trx/ctrl_cmd.py: use a random bind port by default
Since it is not required to specify a bind port to the UDPLink constructor manually, let's use a random one by default, and also allow user to set it from command line. Change-Id: Ib4965ebeec83d9a99b2f026156eb5f5cb20875bf
-rwxr-xr-xsrc/target/fake_trx/ctrl_cmd.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/target/fake_trx/ctrl_cmd.py b/src/target/fake_trx/ctrl_cmd.py
index 3faf8127..83baa197 100755
--- a/src/target/fake_trx/ctrl_cmd.py
+++ b/src/target/fake_trx/ctrl_cmd.py
@@ -4,7 +4,7 @@
# Auxiliary tool to send custom commands via TRX CTRL interface,
# which may be useful for testing and fuzzing
#
-# (C) 2017 by Vadim Yanitskiy <axilirator@gmail.com>
+# (C) 2017-2018 by Vadim Yanitskiy <axilirator@gmail.com>
#
# All Rights Reserved
#
@@ -30,7 +30,7 @@ import sys
from udp_link import UDPLink
COPYRIGHT = \
- "Copyright (C) 2017 by Vadim Yanitskiy <axilirator@gmail.com>\n" \
+ "Copyright (C) 2017-2018 by Vadim Yanitskiy <axilirator@gmail.com>\n" \
"License GPLv2+: GNU GPL version 2 or later " \
"<http://gnu.org/licenses/gpl.html>\n" \
"This is free software: you are free to change and redistribute it.\n" \
@@ -40,6 +40,7 @@ class Application:
# Application variables
remote_addr = "127.0.0.1"
base_port = 5700
+ bind_port = 0
fuzzing = False
def __init__(self):
@@ -51,7 +52,11 @@ class Application:
# Init UDP connection
self.ctrl_link = UDPLink(self.remote_addr,
- self.base_port + 1, self.base_port + 101)
+ self.base_port + 1, self.bind_port)
+
+ # Debug print
+ print("[i] Init CTRL interface (%s)" \
+ % self.ctrl_link.desc_link())
def print_help(self, msg = None):
s = " Usage: " + sys.argv[0] + " [options]\n\n" \
@@ -61,6 +66,7 @@ class Application:
s += " TRX interface specific\n" \
" -r --remote-addr Set remote address (default %s)\n" \
" -p --base-port Set base port number (default %d)\n" \
+ " -P --bind-port Set local port number (default: random)\n" \
" -f --fuzzing Send raw payloads (without CMD)\n" \
print(s % (self.remote_addr, self.base_port))
@@ -71,11 +77,12 @@ class Application:
def parse_argv(self):
try:
opts, args = getopt.getopt(sys.argv[1:],
- "r:p:fh",
+ "r:p:P:fh",
[
"help",
"fuzzing",
"base-port=",
+ "bind-port=",
"remote-addr=",
])
except getopt.GetoptError as err:
@@ -91,6 +98,8 @@ class Application:
self.remote_addr = v
elif o in ("-p", "--base-port"):
self.base_port = int(v)
+ elif o in ("-P", "--bind-port"):
+ self.bind_port = int(v)
elif o in ("-f", "--fuzzing"):
self.fuzzing = True