mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-30 06:49:24 +01:00
Added ping command to Unix plugin
Signed-off-by: Daniel Folkinshteyn <nanotube@users.sourceforge.net>
This commit is contained in:
parent
f6c9543dc3
commit
390b3ec15f
@ -87,5 +87,9 @@ conf.registerGlobalValue(Unix.wtf, 'command',
|
||||
registry.String(utils.findBinaryInPath('wtf') or '', _("""Determines what
|
||||
command will be called for the wtf command.""")))
|
||||
|
||||
conf.registerGroup(Unix, 'ping')
|
||||
conf.registerGlobalValue(Unix.ping, 'command',
|
||||
registry.String(utils.findBinaryInPath('ping') or '', """Determines what
|
||||
command will be called for the ping command."""))
|
||||
|
||||
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
||||
|
@ -256,5 +256,36 @@ class Unix(callbacks.Plugin):
|
||||
'variable appropriately.'))
|
||||
wtf = wrap(wtf, [optional(('literal', ['is'])), 'something'])
|
||||
|
||||
def ping(self, irc, msg, args, host):
|
||||
"""<host or ip>
|
||||
Sends an ICMP echo request to the specified host
|
||||
"""
|
||||
pingCmd = self.registryValue('ping.command')
|
||||
if not pingCmd:
|
||||
irc.error('The ping command is not configured. If one '
|
||||
'is installed, reconfigure '
|
||||
'supybot.plugins.Unix.ping.command appropriately.',
|
||||
Raise=True)
|
||||
else:
|
||||
try: host = host.group(0)
|
||||
except AttributeError: pass
|
||||
|
||||
inst = subprocess.Popen([pingCmd,'-c','1', host],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
stdin=file(os.devnull))
|
||||
|
||||
result = inst.communicate()
|
||||
|
||||
if result[1]: # stderr
|
||||
irc.reply(' '.join(result[1].split()))
|
||||
else:
|
||||
response = result[0].split("\n");
|
||||
irc.reply(' '.join(response[1].split()[3:5]).split(':')[0]
|
||||
+ ': ' + ' '.join(response[-3:]))
|
||||
|
||||
_hostExpr = re.compile(r'^[a-z0-9][a-z0-9\.-]*$', re.I)
|
||||
ping = wrap(ping, [first('ip', ('matches', _hostExpr, 'Invalid hostname'))])
|
||||
|
||||
Class = Unix
|
||||
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
||||
|
@ -65,5 +65,10 @@ if os.name == 'posix':
|
||||
def testFortune(self):
|
||||
self.assertNotError('fortune')
|
||||
|
||||
if utils.findBinaryInPath('ping') is not None:
|
||||
def testPing(self):
|
||||
self.assertNotError('ping')
|
||||
|
||||
|
||||
|
||||
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
||||
|
Loading…
Reference in New Issue
Block a user