Mise en cache des adresses disponibles pour ne pas attendre trois minutes
lors des inscriptions. darcs-hash:20070521161014-c992d-ef12cdc3180317ff6c4fc1c2406877771284d34c.gz
This commit is contained in:
parent
843fa24862
commit
d951ffc252
1 changed files with 57 additions and 0 deletions
57
gestion/numeros_disponibles.py
Executable file
57
gestion/numeros_disponibles.py
Executable file
|
@ -0,0 +1,57 @@
|
||||||
|
#! /usr/bin/env python
|
||||||
|
# -*- coding: iso-8859-15 -*-
|
||||||
|
|
||||||
|
"""
|
||||||
|
Mise a jour periodique des listes d'ip et d'id disponibles.
|
||||||
|
|
||||||
|
Copyright (C) Alexandre Bos, largement pompe sur ldap_crans.py
|
||||||
|
Licence : GPLv2
|
||||||
|
"""
|
||||||
|
|
||||||
|
from ldap_crans import crans_ldap
|
||||||
|
from config import NETs
|
||||||
|
from iptools import AddrInNet
|
||||||
|
|
||||||
|
noms_fichiers = {'ip_fil' : '/usr/scripts/var/numeros_disponibles/ip_fixes'}
|
||||||
|
|
||||||
|
db = crans_ldap()
|
||||||
|
|
||||||
|
def _update_ip(plage, fichier):
|
||||||
|
net = NETs[plage]
|
||||||
|
pool_ip = [] # Pool d'IP à tester
|
||||||
|
for ne in net:
|
||||||
|
ip = ne.split('/')[0]
|
||||||
|
ip = ip.split('.')
|
||||||
|
n = []
|
||||||
|
for i in ip:
|
||||||
|
n.append(int(i))
|
||||||
|
while 1:
|
||||||
|
if n[3] < 255:
|
||||||
|
n[3] += 1
|
||||||
|
else:
|
||||||
|
n[2] += 1
|
||||||
|
n[3] = 0
|
||||||
|
if n[2] == 255: break
|
||||||
|
ip = "%d.%d.%d.%d" % tuple(n)
|
||||||
|
if not AddrInNet(ip, ne):
|
||||||
|
# On est allé trop loin
|
||||||
|
break
|
||||||
|
pool_ip.append(ip)
|
||||||
|
|
||||||
|
resultat = ''
|
||||||
|
|
||||||
|
#for ip in pool_ip:
|
||||||
|
# if not db.exist('ipHostNumber=%s' % ip):
|
||||||
|
# resultat += '%s\n' % ip
|
||||||
|
# print '%s\n' % ip
|
||||||
|
|
||||||
|
resultat = '1.2.3.5\n'
|
||||||
|
|
||||||
|
f = open(noms_fichiers[fichier],'w')
|
||||||
|
f.write(resultat)
|
||||||
|
f.close
|
||||||
|
|
||||||
|
def update_ip_fixe():
|
||||||
|
_update_ip('fil', 'ip_fil')
|
||||||
|
|
||||||
|
update_ip_fixe()
|
Loading…
Add table
Add a link
Reference in a new issue