Skip to content

Commit 4a211f6

Browse files
committed
Added --broken-nat and --delay; bumped to version 0.4.0
1 parent fb32bd7 commit 4a211f6

File tree

5 files changed

+76
-20
lines changed

5 files changed

+76
-20
lines changed

dublintraceroute/__main__.py

+21-2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,21 @@ def parse_args():
6868
t=_dublintraceroute.DEFAULT_MAX_TTL,
6969
),
7070
)
71+
traceroute_parser.add_argument(
72+
'-D', '--delay', type=int,
73+
default=_dublintraceroute.DEFAULT_DELAY,
74+
help='The inter-packet delay (default: {d})'.format(
75+
d=_dublintraceroute.DEFAULT_DELAY,
76+
),
77+
)
78+
traceroute_parser.add_argument(
79+
'-b', '--broken-nat', action='store_true',
80+
default=_dublintraceroute.DEFAULT_BROKEN_NAT,
81+
help=('The network has a broken NAT (e.g. no payload fixup). Try this '
82+
'if you see less hops than expected (default: {b})'.format(
83+
b=_dublintraceroute.DEFAULT_BROKEN_NAT,
84+
)),
85+
)
7186

7287
return parser.parse_args()
7388

@@ -77,15 +92,19 @@ def main():
7792
if args.command == 'trace':
7893
print('Traceroute to {t}'.format(t=args.target))
7994
print(' Source port: {s}, destination port: {d}, num paths: {n}, '
80-
'min TTL: {mint}, max TTL: {maxt}'.format(
95+
'min TTL: {mint}, max TTL: {maxt}, delay: {delay}, '
96+
'broken NAT: {bn}'.format(
8197
s=args.sport,
8298
d=args.dport,
8399
n=args.npaths,
84100
mint=args.min_ttl,
85101
maxt=args.max_ttl,
102+
delay=args.delay,
103+
bn=args.broken_nat,
86104
))
87105
dub = DublinTraceroute(args.target, args.sport, args.dport, args.npaths,
88-
args.min_ttl, args.max_ttl)
106+
args.min_ttl, args.max_ttl, args.delay,
107+
args.broken_nat)
89108
dub.traceroute().pretty_print()
90109
elif args.command == 'plot':
91110
results = json.load(args.jsonfile)

dublintraceroute/dublintraceroute.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@ def __str__(self):
1313
return ('<{self.__class__.__name__} (target={target!r}, '
1414
'sport={sport!r}, dport={dport!r}, '
1515
'npaths={npaths!r}, min_ttl={min_ttl}, '
16-
'max_ttl={max_ttl!r})>'.format(
16+
'max_ttl={max_ttl!r}, delay={delay!r}, '
17+
'broken_nat={broken_nat!r})>'.format(
1718
self=self,
1819
target=self.target,
1920
sport=self.sport,
2021
dport=self.dport,
2122
npaths=self.npaths,
2223
min_ttl=self.min_ttl,
2324
max_ttl=self.max_ttl,
25+
delay=self.delay,
26+
broken_nat=self.broken_nat,
2427
)
2528
)
2629

dublintraceroute/py2/_dublintraceroute.cc

+24-11
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ static PyObject* DublinTraceroute_init(PyObject *self, PyObject *args,
1414
unsigned short npaths = DublinTraceroute::default_npaths;
1515
unsigned short min_ttl = DublinTraceroute::default_min_ttl;
1616
unsigned short max_ttl = DublinTraceroute::default_max_ttl;
17+
unsigned int delay = DublinTraceroute::default_delay;
18+
bool broken_nat = DublinTraceroute::default_broken_nat;
1719
static const char *kwlist[] = { "self", "target", "sport", "dport",
18-
"npaths", "min_ttl", "max_ttl", NULL };
19-
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Os|HHHHH",
20+
"npaths", "min_ttl", "max_ttl", "delay", "broken_nat", NULL };
21+
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Os|HHHHHHH",
2022
(char **)&kwlist, &self, &target, &sport,
21-
&dport, &npaths, &min_ttl, &max_ttl)) {
23+
&dport, &npaths, &min_ttl, &max_ttl, &delay,
24+
&broken_nat)) {
2225
PyErr_BadArgument();
2326
return NULL;
2427
}
@@ -27,13 +30,15 @@ static PyObject* DublinTraceroute_init(PyObject *self, PyObject *args,
2730
DublinTraceroute(target, sport, dport, npaths,
2831
min_ttl, max_ttl));
2932

30-
// Set the instance attributes from the constructor parameters
33+
// Set the instance attributes from the constructor parameters
3134
PyObject *py_sport = PyString_FromString("sport"),
3235
*py_dport = PyString_FromString("dport"),
3336
*py_target = PyString_FromString("target"),
3437
*py_npaths = PyString_FromString("npaths"),
3538
*py_min_ttl = PyString_FromString("min_ttl"),
36-
*py_max_ttl = PyString_FromString("max_ttl");
39+
*py_max_ttl = PyString_FromString("max_ttl"),
40+
*py_delay = PyString_FromString("delay"),
41+
*py_broken_nat = PyString_FromString("broken_nat");
3742

3843
Py_INCREF(py_sport);
3944
Py_INCREF(py_dport);
@@ -48,6 +53,8 @@ static PyObject* DublinTraceroute_init(PyObject *self, PyObject *args,
4853
PyObject_SetAttr(self, py_npaths, Py_BuildValue("i", npaths));
4954
PyObject_SetAttr(self, py_min_ttl, Py_BuildValue("i", min_ttl));
5055
PyObject_SetAttr(self, py_max_ttl, Py_BuildValue("i", max_ttl));
56+
PyObject_SetAttr(self, py_delay, Py_BuildValue("i", delay));
57+
PyObject_SetAttr(self, py_broken_nat, PyBool_FromLong(broken_nat));
5158

5259
Py_INCREF(Py_None);
5360
return Py_None;
@@ -77,12 +84,14 @@ static PyMethodDef DublinTracerouteMethods[] =
7784
"Initialize DublinTraceroute\n"
7885
"\n"
7986
"Arguments:\n"
80-
" target : the target IP address\n"
81-
" srcport : the source UDP port (optional, default=12345)\n"
82-
" dstport : the destination UDP port to start with (optional, default=33434)\n"
83-
" npaths : the number of paths to cover (optional, default=20)\n"
84-
" min_ttl : the maximum Time-To-Live (optiona, default=1)\n"
85-
" max_ttl : the maximum Time-To-Live (optiona, default=30)\n"
87+
" target : the target IP address\n"
88+
" srcport : the source UDP port (optional, default=12345)\n"
89+
" dstport : the destination UDP port to start with (optional, default=33434)\n"
90+
" npaths : the number of paths to cover (optional, default=20)\n"
91+
" min_ttl : the maximum Time-To-Live (optional, default=1)\n"
92+
" max_ttl : the maximum Time-To-Live (optional, default=30)\n"
93+
" delay : the inter-packet delay in milliseconds (optional, default=10ms)"
94+
" broken_nat : the network has a broken NAT configuration (e.g. no payload fixup). Try this if you see less hops than expected"
8695
"\n"
8796
"Return value:\n"
8897
" a JSON object containing the traceroute data. See example below\n"
@@ -139,6 +148,10 @@ init_dublintraceroute(void)
139148
PyInt_FromLong(DublinTraceroute::default_min_ttl));
140149
PyObject_SetAttrString(module, "DEFAULT_MAX_TTL",
141150
PyInt_FromLong(DublinTraceroute::default_max_ttl));
151+
PyObject_SetAttrString(module, "DEFAULT_DELAY",
152+
PyInt_FromLong(DublinTraceroute::default_delay));
153+
PyObject_SetAttrString(module, "DEFAULT_BROKEN_NAT",
154+
PyInt_FromLong(DublinTraceroute::default_broken_nat));
142155

143156
/* create the DublinTraceroute class */
144157
PyObject *classDictDT = PyDict_New();

dublintraceroute/py3/_dublintraceroute.cc

+26-5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ typedef struct {
1616
PyObject *npaths;
1717
PyObject *min_ttl;
1818
PyObject *max_ttl;
19+
PyObject *delay;
20+
PyObject *broken_nat;
1921
} DublinTracerouteClass;
2022

2123

@@ -37,39 +39,48 @@ DublinTraceroute_init(PyObject *self, PyObject *args,
3739
unsigned short npaths = DublinTraceroute::default_npaths;
3840
unsigned short min_ttl = DublinTraceroute::default_min_ttl;
3941
unsigned short max_ttl = DublinTraceroute::default_max_ttl;
42+
unsigned int delay = DublinTraceroute::default_delay;
43+
bool broken_nat = DublinTraceroute::default_broken_nat;
4044
static const char *arglist[] = { "target", "sport", "dport",
41-
"npaths", "min_ttl", "max_ttl", NULL };
42-
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|HHHHH",
45+
"npaths", "min_ttl", "max_ttl", "delay", "broken_nat", NULL };
46+
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|HHHHHHH",
4347
(char **)&arglist, &target, &sport,
44-
&dport, &npaths, &min_ttl, &max_ttl)) {
48+
&dport, &npaths, &min_ttl, &max_ttl, &delay,
49+
&broken_nat)) {
4550
return -1;
4651
}
4752

4853
dublintraceroute = std::make_shared<DublinTraceroute>(
4954
DublinTraceroute(target, sport, dport, npaths,
50-
min_ttl, max_ttl));
55+
min_ttl, max_ttl, delay, broken_nat));
5156

5257
// Set the instance attributes from the constructor parameters
5358
PyObject *py_sport = PyUnicode_FromString("sport"),
5459
*py_dport = PyUnicode_FromString("dport"),
5560
*py_target = PyUnicode_FromString("target"),
5661
*py_npaths = PyUnicode_FromString("npaths"),
5762
*py_min_ttl = PyUnicode_FromString("min_ttl"),
58-
*py_max_ttl = PyUnicode_FromString("max_ttl");
63+
*py_max_ttl = PyUnicode_FromString("max_ttl"),
64+
*py_delay = PyUnicode_FromString("delay"),
65+
*py_broken_nat = PyUnicode_FromString("broken_nat");
5966

6067
Py_INCREF(py_sport);
6168
Py_INCREF(py_dport);
6269
Py_INCREF(py_target);
6370
Py_INCREF(py_npaths);
6471
Py_INCREF(py_min_ttl);
6572
Py_INCREF(py_max_ttl);
73+
Py_INCREF(py_delay);
74+
Py_INCREF(py_broken_nat);
6675

6776
PyObject_SetAttr(self, py_sport, Py_BuildValue("i", sport));
6877
PyObject_SetAttr(self, py_dport, Py_BuildValue("i", dport));
6978
PyObject_SetAttr(self, py_target, Py_BuildValue("s", target));
7079
PyObject_SetAttr(self, py_npaths, Py_BuildValue("i", npaths));
7180
PyObject_SetAttr(self, py_min_ttl, Py_BuildValue("i", min_ttl));
7281
PyObject_SetAttr(self, py_max_ttl, Py_BuildValue("i", max_ttl));
82+
PyObject_SetAttr(self, py_delay, Py_BuildValue("i", delay));
83+
PyObject_SetAttr(self, py_broken_nat, PyBool_FromLong(broken_nat));
7384

7485
Py_INCREF(Py_None);
7586
return 0;
@@ -105,6 +116,10 @@ static PyMemberDef DublinTraceroute_members[] = {
105116
(char *)"minimum TTL"},
106117
{(char *)"max_ttl", T_OBJECT_EX, offsetof(DublinTracerouteClass, max_ttl), 0,
107118
(char *)"maximum TTL"},
119+
{(char *)"delay", T_OBJECT_EX, offsetof(DublinTracerouteClass, delay), 0,
120+
(char *)"inter-packet delay"},
121+
{(char *)"broken_nat", T_OBJECT_EX, offsetof(DublinTracerouteClass, broken_nat), 0,
122+
(char *)"broken NAT flag"},
108123
{NULL} /* Sentinel */
109124
};
110125

@@ -121,6 +136,8 @@ static PyMethodDef DublinTraceroute_methods[] =
121136
" npaths : the number of paths to cover (optional, default=20)\n"
122137
" min_ttl : the minimum Time-To-Live (optiona, default=1)\n"
123138
" max_ttl : the maximum Time-To-Live (optiona, default=30)\n"
139+
" delay : the inter-packet delay in milliseconds (optional, default=10ms)"
140+
" broken_nat : the network has a broken NAT configuration (e.g. no payload fixup). Try this if you see less hops than expected"
124141
"\n"
125142
"Return value:\n"
126143
" a JSON object containing the traceroute data. See example below\n"
@@ -223,5 +240,9 @@ PyInit__dublintraceroute(void)
223240
PyLong_FromLong(DublinTraceroute::default_max_ttl));
224241
PyObject_SetAttrString(module, "DEFAULT_MIN_TTL",
225242
PyLong_FromLong(DublinTraceroute::default_min_ttl));
243+
PyObject_SetAttrString(module, "DEFAULT_DELAY",
244+
PyLong_FromLong(DublinTraceroute::default_delay));
245+
PyObject_SetAttrString(module, "DEFAULT_BROKEN_NAT",
246+
PyLong_FromLong(DublinTraceroute::default_broken_nat));
226247
return module;
227248
}

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
setup(
3030
name='dublintraceroute',
3131
packages=['dublintraceroute'],
32-
version='0.3.1',
32+
version='0.4.0',
3333
author='Andrea Barberio',
3434
author_email='[email protected]',
3535
description='NAT-aware multipath traceroute',

0 commit comments

Comments
 (0)