#!/usr/bin/python # 2017-4-14 first version # Author: DiXingYu import sys import getopt import netsnmp import time def TOTAL_USER(x,y): total_user = len(netsnmp.snmpwalk(netsnmp.Varbind('.1.3.6.1.4.1.9.9.599.1.3.1.1.28'),Version = 2,DestHost=(x),Community=(y))) return total_user def WLAN_USER(x,y): wlan_user = netsnmp.snmpwalk(netsnmp.Varbind('.1.3.6.1.4.1.9.9.599.1.3.1.1.28'),Version = 2,DestHost=(x),Community=(y)) return wlan_user opts, args = getopt.getopt(sys.argv[1:], 'H:C:', [ 'host=', 'community=', 'ssid=', 'list', 'total', 'help' ] ) for option, value in opts: if option in ['--help']: print """ list current SSID : %s -H -C --list show the total user number connect to the wlc: %s -H -C --total show the SSID connect client number: %s -H -C --ssid """ sys.exit() elif option in ['--host', '-H']: hosts = value elif option in ['--community', '-C']: communitys = value elif option in ['--ssid']: SSIDs = value elif option in ['--total']: print "The total user connect to the WLC number is %i"%int(TOTAL_USER(hosts,communitys)),'|' "Total_User=%i"%int(TOTAL_USER(hosts,communitys)) sys.exit() elif option in ['--list']: print "Current used SSID is blowe" for i in set(WLAN_USER(hosts,communitys)): print (i), sys.exit() user_with_ssid = WLAN_USER(hosts,communitys) wlan_count = int(user_with_ssid.count(SSIDs)) print "The SSID %s"%SSIDs + " connect user number is %i"%wlan_count, '|' "%s"%SSIDs + "=%i"%wlan_count