
Ignore-this: c94e57afb3854f47dd5a9933fdf9503c darcs-hash:20090425002901-ffbb2-4f36604cd78d4d0ce819d1dad7e74077ebaa49d1.gz
41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
#! /usr/bin/env python
|
|
# -*- coding: iso-8859-15 -*-
|
|
|
|
# Ajout d'un whos et d'un tracage aux mails d'arpwatch
|
|
# Auteurs : Stéphane Glondu, Cyril Cohen
|
|
# Licence : GPLv2
|
|
|
|
import sys, os, re, smtplib
|
|
from commands import getstatusoutput
|
|
|
|
sys.path.append('/usr/scripts/gestion/tools')
|
|
from locate_mac import trace_machine, format_mac, info_machine
|
|
|
|
find_mac = re.compile(r'[0-9A-Fa-f]{1,2}(?::[0-9A-Fa-f]{1,2}){5}')
|
|
|
|
|
|
def get_machine(unformated_mac):
|
|
mac = format_mac(unformated_mac)
|
|
return u"\n" + info_machine(mac) + u"\n" + trace_machine(mac)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
texte = sys.stdin.read().decode('ISO-8859-15')
|
|
# On récupère les destinataires dans les arguments (très ad hoc)
|
|
recipients = sys.argv[2].split(',')
|
|
# On complète le message
|
|
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 += u'\n'
|
|
texte += u''.join(traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback))
|
|
texte += '\n-- \narpwatch_sendmail.py\n'
|
|
|
|
smtp = smtplib.SMTP()
|
|
smtp.connect()
|
|
smtp.sendmail("arpwatch@crans.org", recipients, texte.encode('ISO-8859-15'))
|
|
smtp.quit()
|