mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-07 19:49:23 +01:00
Added ping command to Unix plugin
Signed-off-by: Daniel Folkinshteyn <nanotube@users.sourceforge.net>
This commit is contained in:
parent
67a41f6626
commit
a8e91a58a0
@ -85,5 +85,9 @@ conf.registerGlobalValue(Unix.wtf, 'command',
|
|||||||
registry.String(utils.findBinaryInPath('wtf') or '', """Determines what
|
registry.String(utils.findBinaryInPath('wtf') or '', """Determines what
|
||||||
command will be called for the wtf command."""))
|
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:
|
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
||||||
|
@ -249,5 +249,36 @@ class Unix(callbacks.Plugin):
|
|||||||
'variable appropriately.')
|
'variable appropriately.')
|
||||||
wtf = wrap(wtf, [optional(('literal', ['is'])), 'something'])
|
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
|
Class = Unix
|
||||||
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
||||||
|
@ -64,5 +64,10 @@ if os.name == 'posix':
|
|||||||
def testFortune(self):
|
def testFortune(self):
|
||||||
self.assertNotError('fortune')
|
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:
|
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
||||||
|
Loading…
Reference in New Issue
Block a user