37 lines
1.1 KiB
Python
Executable file
37 lines
1.1 KiB
Python
Executable file
#! /usr/bin/env python
|
|
# -*- coding: iso-8859-15 -*-
|
|
|
|
# Ajout d'un whos aux mails d'arpwatch
|
|
# Auteur : Stéphane Glondu
|
|
# Licence : GPLv2
|
|
|
|
import sys, os, sre, smtplib
|
|
|
|
find_mac = sre.compile(r'[0-9A-Fa-f]{1,2}(?::[0-9A-Fa-f]{1,2}){5}')
|
|
|
|
def get_machine(mac):
|
|
s = os.popen("sudo /usr/scripts/gestion/whos.py mac=%s" % mac).readlines()
|
|
if len(s) == 1:
|
|
return ""
|
|
else:
|
|
# On supprime la première ligne et les couleurs
|
|
s = "\n" + "".join(s[1:])
|
|
s = sre.sub('\x1b\[1;([0-9]|[0-9][0-9])m', '', s)
|
|
return s
|
|
|
|
if __name__ == "__main__":
|
|
texte = sys.stdin.read()
|
|
try:
|
|
macs = find_mac.findall(texte)
|
|
for mac in macs:
|
|
texte += get_machine(mac)
|
|
except:
|
|
# En cas d'exception, on envoie le traceback
|
|
import traceback
|
|
texte += '\n'
|
|
texte += '\n'.join(traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback))
|
|
test += '\n-- \narpwatch_sendmail.py\n'
|
|
smtp = smtplib.SMTP()
|
|
smtp.connect()
|
|
smtp.sendmail("arpwatch@crans.org", "root@crans.org", texte)
|
|
smtp.quit()
|