From 5db3faca7a09a226aee6ca8f17a5015f79200e86 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Fri, 11 Mar 2016 21:12:04 +0100 Subject: [PATCH] Unix: Add support for -4 and -6 in @ping. Closes GH-1224. --- plugins/Unix/plugin.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/plugins/Unix/plugin.py b/plugins/Unix/plugin.py index cef3b55fb..97b1230c0 100644 --- a/plugins/Unix/plugin.py +++ b/plugins/Unix/plugin.py @@ -272,11 +272,14 @@ class Unix(callbacks.Plugin): def _make_ping(command): def f(self, irc, msg, args, optlist, host): - """[--c ] [--i ] [--t ] [--W ] + """[--c ] [--i ] [--t ] [--W ] [--4|--6] + Sends an ICMP echo request to the specified host. The arguments correspond with those listed in ping(8). --c is limited to 10 packets or less (default is 5). --i is limited to 5 or less. --W is limited to 10 or less. + --4 and --6 can be used if and only if the system has a unified + ping command. """ pingCmd = self.registryValue(registry.join([command, 'command'])) if not pingCmd: @@ -294,7 +297,8 @@ class Unix(callbacks.Plugin): if opt == 'i' and val > 5: val = 5 if opt == 'W' and val > 10: val = 10 args.append('-%s' % opt) - args.append(str(val)) + if opt not in ('4', '6'): + args.append(str(val)) if '-c' not in args: args.append('-c') args.append('5') @@ -323,7 +327,8 @@ class Unix(callbacks.Plugin): f.__name__ = command _hostExpr = re.compile(r'^[a-z0-9][a-z0-9\.-]*[a-z0-9]$', re.I) return thread(wrap(f, [getopts({'c':'positiveInt','i':'float', - 't':'positiveInt','W':'positiveInt'}), + 't':'positiveInt','W':'positiveInt', + '4':'', '6':''}), first('ip', ('matches', _hostExpr, 'Invalid hostname'))])) ping = _make_ping('ping')