script qui permet de trouver la liste des personnes associes aux bornes wifi
on peut mettre une adresse mac comme argument il faut etre root pour executer le script car il faut la cl ssh darcs-hash:20050411180745-4ec08-df58ffb49eced0c35399d457d06ac9a1de0c3fd7.gz
This commit is contained in:
parent
280d588617
commit
e9ee88c8c6
1 changed files with 84 additions and 0 deletions
84
gestion/locate-wifi.py
Executable file
84
gestion/locate-wifi.py
Executable file
|
@ -0,0 +1,84 @@
|
|||
#! /usr/bin/env python
|
||||
# -*- coding: iso-8859-15 -*-
|
||||
|
||||
import sys
|
||||
sys.path.append('/usr/scripts/gestion')
|
||||
from whos import borne_clients, borne_etat
|
||||
from ldap_crans import crans_ldap
|
||||
from time import sleep
|
||||
from affich_tools import coul
|
||||
import threading
|
||||
from os import getuid
|
||||
|
||||
# il faut être root
|
||||
if getuid() :
|
||||
print 'Il faut être root !'
|
||||
sys.exit(1)
|
||||
|
||||
# connexion à la base de données
|
||||
db = crans_ldap()
|
||||
|
||||
# décompostion des arguments
|
||||
try :
|
||||
mac = ":".join([i.zfill(2) for i in sys.argv[1].split(":")]).upper()
|
||||
except :
|
||||
mac = None
|
||||
|
||||
# dit si une mac a déja été traitée
|
||||
mac_done=[]
|
||||
def done (mac) :
|
||||
global mac_done
|
||||
if mac in mac_done :
|
||||
return True
|
||||
else :
|
||||
mac_done.append(mac)
|
||||
return False
|
||||
|
||||
# classe d'interrogation des bornes
|
||||
class interroge_borne (threading.Thread) :
|
||||
def __init__ (self, db, borne, mac = None) :
|
||||
threading.Thread.__init__(self)
|
||||
self.borne = borne
|
||||
self.mac = mac
|
||||
self.db = db
|
||||
self.start()
|
||||
|
||||
def aff_client (self, mac, rssi) :
|
||||
if done(mac) :
|
||||
return
|
||||
|
||||
res = db.search("mac=%s" % mac)['machine']
|
||||
if not res:
|
||||
client_nom = '????'
|
||||
coul_rssi = 'rouge'
|
||||
rssi = 0
|
||||
else:
|
||||
# On va choisir la bonne couleur pour le RSSI
|
||||
if rssi > -77:
|
||||
coul_rssi = 'vert'
|
||||
elif rssi > -90:
|
||||
coul_rssi = 'jaune'
|
||||
else:
|
||||
coul_rssi = 'rouge'
|
||||
print '%-10s %-30s (%-15s, RSSI: %s)' % (self.borne.nom().split('.')[0], res[0].proprietaire().Nom(), res[0].nom().split('.')[0],coul("%d" % rssi, coul_rssi))
|
||||
|
||||
def run (self) :
|
||||
nom = self.borne.nom()
|
||||
if not borne_etat(nom) :
|
||||
return
|
||||
clients = borne_clients(nom)
|
||||
for (mac, rssi) in clients :
|
||||
if not self.mac or self.mac == mac.lower() :
|
||||
self.aff_client(mac,rssi)
|
||||
|
||||
# on onterroge trois fois car il donne pas toujours les clients
|
||||
for i in range(0,3) :
|
||||
# on interroge les bornes
|
||||
resultat = {}
|
||||
bornes = db.search('canal=*')['machine']
|
||||
for borne in bornes :
|
||||
interroge_borne(db, borne, mac)
|
||||
|
||||
# on attend la fin de threads
|
||||
while len(threading.enumerate()) > 1 :
|
||||
sleep(1)
|
Loading…
Add table
Add a link
Reference in a new issue