Skip to content

Commit

Permalink
Added --broken-nat and --delay; bumped to version 0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
insomniacslk committed Oct 4, 2016
1 parent fb32bd7 commit 4a211f6
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 20 deletions.
23 changes: 21 additions & 2 deletions dublintraceroute/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,21 @@ def parse_args():
t=_dublintraceroute.DEFAULT_MAX_TTL,
),
)
traceroute_parser.add_argument(
'-D', '--delay', type=int,
default=_dublintraceroute.DEFAULT_DELAY,
help='The inter-packet delay (default: {d})'.format(
d=_dublintraceroute.DEFAULT_DELAY,
),
)
traceroute_parser.add_argument(
'-b', '--broken-nat', action='store_true',
default=_dublintraceroute.DEFAULT_BROKEN_NAT,
help=('The network has a broken NAT (e.g. no payload fixup). Try this '
'if you see less hops than expected (default: {b})'.format(
b=_dublintraceroute.DEFAULT_BROKEN_NAT,
)),
)

return parser.parse_args()

Expand All @@ -77,15 +92,19 @@ def main():
if args.command == 'trace':
print('Traceroute to {t}'.format(t=args.target))
print(' Source port: {s}, destination port: {d}, num paths: {n}, '
'min TTL: {mint}, max TTL: {maxt}'.format(
'min TTL: {mint}, max TTL: {maxt}, delay: {delay}, '
'broken NAT: {bn}'.format(
s=args.sport,
d=args.dport,
n=args.npaths,
mint=args.min_ttl,
maxt=args.max_ttl,
delay=args.delay,
bn=args.broken_nat,
))
dub = DublinTraceroute(args.target, args.sport, args.dport, args.npaths,
args.min_ttl, args.max_ttl)
args.min_ttl, args.max_ttl, args.delay,
args.broken_nat)
dub.traceroute().pretty_print()
elif args.command == 'plot':
results = json.load(args.jsonfile)
Expand Down
5 changes: 4 additions & 1 deletion dublintraceroute/dublintraceroute.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@ def __str__(self):
return ('<{self.__class__.__name__} (target={target!r}, '
'sport={sport!r}, dport={dport!r}, '
'npaths={npaths!r}, min_ttl={min_ttl}, '
'max_ttl={max_ttl!r})>'.format(
'max_ttl={max_ttl!r}, delay={delay!r}, '
'broken_nat={broken_nat!r})>'.format(
self=self,
target=self.target,
sport=self.sport,
dport=self.dport,
npaths=self.npaths,
min_ttl=self.min_ttl,
max_ttl=self.max_ttl,
delay=self.delay,
broken_nat=self.broken_nat,
)
)

Expand Down
35 changes: 24 additions & 11 deletions dublintraceroute/py2/_dublintraceroute.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ static PyObject* DublinTraceroute_init(PyObject *self, PyObject *args,
unsigned short npaths = DublinTraceroute::default_npaths;
unsigned short min_ttl = DublinTraceroute::default_min_ttl;
unsigned short max_ttl = DublinTraceroute::default_max_ttl;
unsigned int delay = DublinTraceroute::default_delay;
bool broken_nat = DublinTraceroute::default_broken_nat;
static const char *kwlist[] = { "self", "target", "sport", "dport",
"npaths", "min_ttl", "max_ttl", NULL };
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Os|HHHHH",
"npaths", "min_ttl", "max_ttl", "delay", "broken_nat", NULL };
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Os|HHHHHHH",
(char **)&kwlist, &self, &target, &sport,
&dport, &npaths, &min_ttl, &max_ttl)) {
&dport, &npaths, &min_ttl, &max_ttl, &delay,
&broken_nat)) {
PyErr_BadArgument();
return NULL;
}
Expand All @@ -27,13 +30,15 @@ static PyObject* DublinTraceroute_init(PyObject *self, PyObject *args,
DublinTraceroute(target, sport, dport, npaths,
min_ttl, max_ttl));

// Set the instance attributes from the constructor parameters
// Set the instance attributes from the constructor parameters
PyObject *py_sport = PyString_FromString("sport"),
*py_dport = PyString_FromString("dport"),
*py_target = PyString_FromString("target"),
*py_npaths = PyString_FromString("npaths"),
*py_min_ttl = PyString_FromString("min_ttl"),
*py_max_ttl = PyString_FromString("max_ttl");
*py_max_ttl = PyString_FromString("max_ttl"),
*py_delay = PyString_FromString("delay"),
*py_broken_nat = PyString_FromString("broken_nat");

Py_INCREF(py_sport);
Py_INCREF(py_dport);
Expand All @@ -48,6 +53,8 @@ static PyObject* DublinTraceroute_init(PyObject *self, PyObject *args,
PyObject_SetAttr(self, py_npaths, Py_BuildValue("i", npaths));
PyObject_SetAttr(self, py_min_ttl, Py_BuildValue("i", min_ttl));
PyObject_SetAttr(self, py_max_ttl, Py_BuildValue("i", max_ttl));
PyObject_SetAttr(self, py_delay, Py_BuildValue("i", delay));
PyObject_SetAttr(self, py_broken_nat, PyBool_FromLong(broken_nat));

Py_INCREF(Py_None);
return Py_None;
Expand Down Expand Up @@ -77,12 +84,14 @@ static PyMethodDef DublinTracerouteMethods[] =
"Initialize DublinTraceroute\n"
"\n"
"Arguments:\n"
" target : the target IP address\n"
" srcport : the source UDP port (optional, default=12345)\n"
" dstport : the destination UDP port to start with (optional, default=33434)\n"
" npaths : the number of paths to cover (optional, default=20)\n"
" min_ttl : the maximum Time-To-Live (optiona, default=1)\n"
" max_ttl : the maximum Time-To-Live (optiona, default=30)\n"
" target : the target IP address\n"
" srcport : the source UDP port (optional, default=12345)\n"
" dstport : the destination UDP port to start with (optional, default=33434)\n"
" npaths : the number of paths to cover (optional, default=20)\n"
" min_ttl : the maximum Time-To-Live (optional, default=1)\n"
" max_ttl : the maximum Time-To-Live (optional, default=30)\n"
" delay : the inter-packet delay in milliseconds (optional, default=10ms)"
" broken_nat : the network has a broken NAT configuration (e.g. no payload fixup). Try this if you see less hops than expected"
"\n"
"Return value:\n"
" a JSON object containing the traceroute data. See example below\n"
Expand Down Expand Up @@ -139,6 +148,10 @@ init_dublintraceroute(void)
PyInt_FromLong(DublinTraceroute::default_min_ttl));
PyObject_SetAttrString(module, "DEFAULT_MAX_TTL",
PyInt_FromLong(DublinTraceroute::default_max_ttl));
PyObject_SetAttrString(module, "DEFAULT_DELAY",
PyInt_FromLong(DublinTraceroute::default_delay));
PyObject_SetAttrString(module, "DEFAULT_BROKEN_NAT",
PyInt_FromLong(DublinTraceroute::default_broken_nat));

/* create the DublinTraceroute class */
PyObject *classDictDT = PyDict_New();
Expand Down
31 changes: 26 additions & 5 deletions dublintraceroute/py3/_dublintraceroute.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ typedef struct {
PyObject *npaths;
PyObject *min_ttl;
PyObject *max_ttl;
PyObject *delay;
PyObject *broken_nat;
} DublinTracerouteClass;


Expand All @@ -37,39 +39,48 @@ DublinTraceroute_init(PyObject *self, PyObject *args,
unsigned short npaths = DublinTraceroute::default_npaths;
unsigned short min_ttl = DublinTraceroute::default_min_ttl;
unsigned short max_ttl = DublinTraceroute::default_max_ttl;
unsigned int delay = DublinTraceroute::default_delay;
bool broken_nat = DublinTraceroute::default_broken_nat;
static const char *arglist[] = { "target", "sport", "dport",
"npaths", "min_ttl", "max_ttl", NULL };
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|HHHHH",
"npaths", "min_ttl", "max_ttl", "delay", "broken_nat", NULL };
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|HHHHHHH",
(char **)&arglist, &target, &sport,
&dport, &npaths, &min_ttl, &max_ttl)) {
&dport, &npaths, &min_ttl, &max_ttl, &delay,
&broken_nat)) {
return -1;
}

dublintraceroute = std::make_shared<DublinTraceroute>(
DublinTraceroute(target, sport, dport, npaths,
min_ttl, max_ttl));
min_ttl, max_ttl, delay, broken_nat));

// Set the instance attributes from the constructor parameters
PyObject *py_sport = PyUnicode_FromString("sport"),
*py_dport = PyUnicode_FromString("dport"),
*py_target = PyUnicode_FromString("target"),
*py_npaths = PyUnicode_FromString("npaths"),
*py_min_ttl = PyUnicode_FromString("min_ttl"),
*py_max_ttl = PyUnicode_FromString("max_ttl");
*py_max_ttl = PyUnicode_FromString("max_ttl"),
*py_delay = PyUnicode_FromString("delay"),
*py_broken_nat = PyUnicode_FromString("broken_nat");

Py_INCREF(py_sport);
Py_INCREF(py_dport);
Py_INCREF(py_target);
Py_INCREF(py_npaths);
Py_INCREF(py_min_ttl);
Py_INCREF(py_max_ttl);
Py_INCREF(py_delay);
Py_INCREF(py_broken_nat);

PyObject_SetAttr(self, py_sport, Py_BuildValue("i", sport));
PyObject_SetAttr(self, py_dport, Py_BuildValue("i", dport));
PyObject_SetAttr(self, py_target, Py_BuildValue("s", target));
PyObject_SetAttr(self, py_npaths, Py_BuildValue("i", npaths));
PyObject_SetAttr(self, py_min_ttl, Py_BuildValue("i", min_ttl));
PyObject_SetAttr(self, py_max_ttl, Py_BuildValue("i", max_ttl));
PyObject_SetAttr(self, py_delay, Py_BuildValue("i", delay));
PyObject_SetAttr(self, py_broken_nat, PyBool_FromLong(broken_nat));

Py_INCREF(Py_None);
return 0;
Expand Down Expand Up @@ -105,6 +116,10 @@ static PyMemberDef DublinTraceroute_members[] = {
(char *)"minimum TTL"},
{(char *)"max_ttl", T_OBJECT_EX, offsetof(DublinTracerouteClass, max_ttl), 0,
(char *)"maximum TTL"},
{(char *)"delay", T_OBJECT_EX, offsetof(DublinTracerouteClass, delay), 0,
(char *)"inter-packet delay"},
{(char *)"broken_nat", T_OBJECT_EX, offsetof(DublinTracerouteClass, broken_nat), 0,
(char *)"broken NAT flag"},
{NULL} /* Sentinel */
};

Expand All @@ -121,6 +136,8 @@ static PyMethodDef DublinTraceroute_methods[] =
" npaths : the number of paths to cover (optional, default=20)\n"
" min_ttl : the minimum Time-To-Live (optiona, default=1)\n"
" max_ttl : the maximum Time-To-Live (optiona, default=30)\n"
" delay : the inter-packet delay in milliseconds (optional, default=10ms)"
" broken_nat : the network has a broken NAT configuration (e.g. no payload fixup). Try this if you see less hops than expected"
"\n"
"Return value:\n"
" a JSON object containing the traceroute data. See example below\n"
Expand Down Expand Up @@ -223,5 +240,9 @@ PyInit__dublintraceroute(void)
PyLong_FromLong(DublinTraceroute::default_max_ttl));
PyObject_SetAttrString(module, "DEFAULT_MIN_TTL",
PyLong_FromLong(DublinTraceroute::default_min_ttl));
PyObject_SetAttrString(module, "DEFAULT_DELAY",
PyLong_FromLong(DublinTraceroute::default_delay));
PyObject_SetAttrString(module, "DEFAULT_BROKEN_NAT",
PyLong_FromLong(DublinTraceroute::default_broken_nat));
return module;
}
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
setup(
name='dublintraceroute',
packages=['dublintraceroute'],
version='0.3.1',
version='0.4.0',
author='Andrea Barberio',
author_email='[email protected]',
description='NAT-aware multipath traceroute',
Expand Down

0 comments on commit 4a211f6

Please sign in to comment.