From dd32a30814472f428f2aae00b24a4627815f18a4 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Tue, 18 Aug 2015 01:25:54 +0200 Subject: [PATCH] =?UTF-8?q?Passage=20de=20stats=5Fip=20=C3=A0=20lc=5Fldap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/stats_ip.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/utils/stats_ip.py b/utils/stats_ip.py index 52bb4b03..e09c14df 100755 --- a/utils/stats_ip.py +++ b/utils/stats_ip.py @@ -1,21 +1,22 @@ -#! /usr/bin/env python +#!/bin/bash /usr/scripts/python.sh # -*- coding: utf-8 -*- -import sys -sys.path.append('/usr/scripts/gestion') -from ldap_crans import crans_ldap +from lc_ldap import shortcuts from config import NETs from iptools import AddrInNet -ips = [ x.ip() for x in crans_ldap().search('ip=*')['machine'] ] +ldap = shortcuts.lc_ldap_readonly() + + +ips = [ unicode(x['ipHostNumber'][0]) for x in ldap.search(u'(ipHostNumber=*)',sizelimit=10000)] for n in NETs: - + nb_total = 0 for net in NETs[n]: nb_total += 2 ** ( 32 - int( net.split('/')[1] ) ) - + nb_occupe = len( [ ip for ip in ips if AddrInNet( ip, NETs[n] ) ] ) - + print '%12s %2s%% (%s/%s)' % (n, 100*nb_occupe/nb_total, nb_occupe, nb_total)