コード例 #1
0
def scoutCreateSsid5(ip, username, password, ssid, wpa2Pass, vlan, bridgeGroup, radioSub, gigaSub):
    """Function that deploys a 5GHz SSID to an AP
    using user provided arguments.
    """
    scoutSsh = scout_auth.sshInfo(ip=ip, username=username, password=password)
    jinjaEnv = scout_env.scoutJinjaEnv()
    commandDebug = scout_env.scoutEnv()
    ssid = ssid
    wpa2Pass = wpa2Pass
    vlan = vlan
    bridgeGroup = bridgeGroup
    radioSub = radioSub
    gigaSub = gigaSub
    cmdTemplate = jinjaEnv.get_template("scout_create_ssid_5")
    cmds = cmdTemplate.render(password=password,ssid=ssid,wpa2Pass=wpa2Pass,vlan=vlan,bridgeGroup=bridgeGroup,radioSub=radioSub,gigaSub=gigaSub)
    scoutCommands = cmds.splitlines()
    channel = scoutSsh.invoke_shell()
    print("INFO: Deploying 5GHz SSID {0} to {1}...".format(ssid,ip))
    for command in scoutCommands:
        channel.send('{}\n'.format(command))
        if commandDebug == "on":
            commands = channel.recv(65535)
            print(commands)
        time.sleep(.10)
    scoutSsh.close()
コード例 #2
0
def scoutChangeIp(ip, username, password, newIp, subnetMask):
    """Function that identifies SSH info, collects sys args,
    calls the scout_change_ap_ip command set, opens a SSH connection
    to the AP, executes the IP change, terminates the old SSH connection,
    opens a new one, and runs the scout_do_wr command set to save new IP
    change.
    """
    scoutSsh = scout_auth.sshInfo(ip=ip, username=username, password=password)
    jinjaEnv = scout_env.scoutJinjaEnv()
    commandDebug = scout_env.scoutEnv()
    newIp = newIp
    subnetMask = subnetMask
    cmdTemplate = jinjaEnv.get_template("scout_change_ap_ip")
    cmds = cmdTemplate.render(password=password,
                              newIp=newIp,
                              subnetMask=subnetMask)
    scoutCommands = cmds.splitlines()
    channel = scoutSsh.invoke_shell()
    print("INFO: Changing IP from {0} to {1}...".format(ip, newIp))
    for command in scoutCommands:
        channel.send('{}\n'.format(command))
        if commandDebug == "on":
            commands = channel.recv(65535)
            print(commands)
        time.sleep(.10)
    scoutSsh.close()
    scoutDoWr(ip=newIp, username=username, password=password)
コード例 #3
0
def scoutCreateSsid24Radius(ip, username, password, ssid, vlan, bridgeGroup, radioSub, gigaSub, radiusIp, sharedSecret, authPort, acctPort, radiusTimeout, radiusGroup, methodList):
    """Function that deploys a 2.4GHz 802.1x SSID to an 
    AP using user provided arguments.
    """
    scoutSsh = scout_auth.sshInfo(ip=ip, username=username, password=password)
    jinjaEnv = scout_env.scoutJinjaEnv()
    commandDebug = scout_env.scoutEnv()
    ssid = ssid
    vlan = vlan
    bridgeGroup = bridgeGroup
    radioSub = radioSub
    gigaSub = gigaSub
    radiusIp = radiusIp
    sharedSecret = sharedSecret
    authPort = authPort
    acctPort = acctPort
    radiusTimeout = radiusTimeout
    radiusGroup = radiusGroup
    methodList = methodList
    cmdTemplate = jinjaEnv.get_template("scout_create_radius_ssid_24")
    cmds = cmdTemplate.render(password=password,ssid=ssid,vlan=vlan,bridgeGroup=bridgeGroup,radioSub=radioSub,gigaSub=gigaSub,radiusIp=radiusIp,sharedSecret=sharedSecret,authPort=authPort,acctPort=acctPort,radiusTimeout=radiusTimeout,radiusGroup=radiusGroup,methodList=methodList)
    scoutCommands = cmds.splitlines()
    channel = scoutSsh.invoke_shell()
    print("INFO: Deploying 2.4GHz RADIUS SSID {0} to {1}...".format(ssid,ip))
    for command in scoutCommands:
        channel.send('{}\n'.format(command))
        if commandDebug == "on":
            commands = channel.recv(65535)
            print(commands)
        time.sleep(.10)
    scoutSsh.close()
コード例 #4
0
def scoutLed(ip, username, password):
    """Function that opens a SSH connection to the AP
    and runs led flash 30.
    """
    scoutSsh = scout_auth.sshInfo(ip=ip, username=username, password=password)
    print("INFO: Flashing pretty lights on {}...".format(ip))
    stdin, stdout, stderr = scoutSsh.exec_command("led flash 30\n")
    scoutSsh.close()
コード例 #5
0
def scoutGetUptime(ip, username, password):
    """Function that retrieves AP uptime via show version."""
    scoutSsh = scout_auth.sshInfo(ip=ip, username=username, password=password)
    stdin, stdout, stderr = scoutSsh.exec_command("show version\n")
    sshOut = stdout.read().splitlines()
    getApUptime = sshOut[8].decode('ascii').strip("\n")
    scoutSsh.close()
    return getApUptime
コード例 #6
0
def scoutGetSpeed(ip, username, password):
    """Function that reports speed of Gi0/0 in Mbps."""
    scoutSsh = scout_auth.sshInfo(ip=ip, username=username, password=password)
    stdin, stdout, stderr = scoutSsh.exec_command("sho int gi0\n")
    sshOut = stdout.read()
    sshBandwidth = sshOut.decode('ascii').strip("\n").split(",")
    getBandwidth = sshBandwidth[9].strip("Mbps")
    scoutSsh.close()
    return getBandwidth
コード例 #7
0
def scoutGetArp(ip, username, password):
    """Function that opens a SSH connection to the AP
    and runs show ip arp to gather ARP table.
    """
    scoutSsh = scout_auth.sshInfo(ip=ip, username=username, password=password)
    stdin, stdout, stderr = scoutSsh.exec_command("show ip arp\n")
    sshOut = stdout.read()
    getArpTable = sshOut.decode('ascii').strip("\n").lstrip()
    scoutSsh.close()
    return getArpTable
コード例 #8
0
def scoutGetSerial(ip, username, password):
    """Function that reports the serial number of AP."""
    scoutSsh = scout_auth.sshInfo(ip=ip, username=username, password=password)
    stdin, stdout, stderr = scoutSsh.exec_command("show inventory\n")
    sshOut = stdout.read()
    getSerialString = sshOut.decode('ascii').strip("\n")
    apSerialRegex = re.compile(r'\w\w\w\w\w\w\w\w\w\w\w')
    getApSerial = apSerialRegex.search(getSerialString).group(0)
    scoutSsh.close()
    return getApSerial
コード例 #9
0
def scoutGetModel(ip, username, password):
    """Function that reports the model ID of AP."""
    scoutSsh = scout_auth.sshInfo(ip=ip, username=username, password=password)
    stdin, stdout, stderr = scoutSsh.exec_command("show version\n")
    sshOut = stdout.read()
    getModelString = sshOut.decode('ascii').strip("\n")
    apModelRegex = re.compile(r'\w\w\w\-\w\w\w\w\w\w\w\w\-\w-\w\w')
    getApModel = apModelRegex.search(getModelString).group(0)
    scoutSsh.close()
    return getApModel
コード例 #10
0
def scoutGetMac(ip, username, password):
    """Function that reports back the MAC address of AP."""
    scoutSsh = scout_auth.sshInfo(ip=ip, username=username, password=password)
    macAddrRegex = re.compile(r'\w\w\w\w.\w\w\w\w.\w\w\w\w')
    stdin, stdout, stderr = scoutSsh.exec_command("show int gi0\n")
    sshOut = stdout.read()
    intList = sshOut.decode('ascii').strip("\n").split(",")
    getMac = macAddrRegex.search(intList[2]).group(0)
    scoutSsh.close()
    return getMac
コード例 #11
0
def scoutCountClients(ip, username, password):
    """Function that reports the number of active clients on
    AP via show dot11 associations.
    """
    scoutSsh = scout_auth.sshInfo(ip=ip, username=username, password=password)
    stdin, stdout, stderr = scoutSsh.exec_command("show dot11 associations\n")
    sshOut = stdout.read()
    scoutSsh.close()
    countClient = sshOut.decode('ascii').strip("\n")
    macAddrRegex = re.compile(r'\w\w\w\w\.\w\w\w\w\.\w\w\w\w')
    searchMacAddr = macAddrRegex.findall(countClient)
    totalClients = len(searchMacAddr)
    return totalClients
コード例 #12
0
def scoutGetHostname(ip, username, password):
    """Function that retrieves AP hostname via show version."""
    scoutSsh = scout_auth.sshInfo(ip=ip, username=username, password=password)
    jinjaEnv = scout_env.scoutJinjaEnv()
    cmdTemplate = jinjaEnv.get_template("scout_get_hostname")
    cmds = cmdTemplate.render(password=password)
    scoutCommands = cmds.splitlines()
    channel = scoutSsh.invoke_shell()
    for command in scoutCommands:
        channel.send('{}\n'.format(command))
        time.sleep(.10)
    getHostname = channel.recv(65535).decode('ascii').strip("\n").strip(
        ">").lstrip()
    scoutSsh.close()
    return getHostname
コード例 #13
0
def scoutGetLocation(ip, username, password):
    """Function that retrieves AP location via show snmp location."""
    scoutSsh = scout_auth.sshInfo(ip=ip, username=username, password=password)
    jinjaEnv = scout_env.scoutJinjaEnv()
    cmdTemplate = jinjaEnv.get_template("scout_get_location")
    cmds = cmdTemplate.render(password=password)
    scoutCommands = cmds.splitlines()
    channel = scoutSsh.invoke_shell()
    for command in scoutCommands:
        channel.send('{}\n'.format(command))
        time.sleep(.10)
    if channel.recv_ready():
        sshReturn = channel.recv(65535)
        location = sshReturn.decode('ascii').splitlines()
    scoutSsh.close()
    return location[4]
コード例 #14
0
def scoutDisableRadius(ip, username, password):
    """Function that disables RADIUS on AP."""
    scoutSsh = scout_auth.sshInfo(ip=ip, username=username, password=password)
    jinjaEnv = scout_env.scoutJinjaEnv()
    commandDebug = scout_env.scoutEnv()
    cmdTemplate = jinjaEnv.get_template("scout_disable_ap_radius")
    cmds = cmdTemplate.render(password=password)
    scoutCommands = cmds.splitlines()
    channel = scoutSsh.invoke_shell()
    print("INFO: Disabling RADIUS on {}...".format(ip))
    for command in scoutCommands:
        channel.send('{}\n'.format(command))
        if commandDebug == "on":
            commands = channel.recv(65535)
            print(commands)
        time.sleep(.10)
    scoutSsh.close()
コード例 #15
0
def scoutWriteDefault(ip, username, password):
    """Function that wipes AP memory back to default."""
    scoutSsh = scout_auth.sshInfo(ip=ip, username=username, password=password)
    jinjaEnv = scout_env.scoutJinjaEnv()
    commandDebug = scout_env.scoutEnv()
    cmdTemplate = jinjaEnv.get_template("scout_write_default")
    cmds = cmdTemplate.render(password=password)
    scoutCommands = cmds.splitlines()
    channel = scoutSsh.invoke_shell()
    print("INFO: Erasing config on {}...".format(ip))
    for command in scoutCommands:
        channel.send('{}\n'.format(command))
        if commandDebug == "on":
            commands = channel.recv(65535)
            print(commands)
        time.sleep(.10)
    scoutSsh.close()
コード例 #16
0
def scoutDoWr(ip, username, password):
    """Function that performs write command on AP."""
    scoutSsh = scout_auth.sshInfo(ip=ip, username=username, password=password)
    jinjaEnv = scout_env.scoutJinjaEnv()
    commandDebug = scout_env.scoutEnv()
    cmdTemplate = jinjaEnv.get_template("scout_do_wr")
    cmds = cmdTemplate.render(password=password)
    scoutCommands = cmds.splitlines()
    channel = scoutSsh.invoke_shell()
    print("INFO: Committing changes on {}...".format(ip))
    for command in scoutCommands:
        channel.send('{}\n'.format(command))
        if commandDebug == "on":
            commands = channel.recv(65535)
            print(commands)
        time.sleep(.10)
    scoutSsh.close()
コード例 #17
0
def scoutChangeName(ip, username, password, apName):
    """Function that changes the hostname of AP."""
    scoutSsh = scout_auth.sshInfo(ip=ip, username=username, password=password)
    jinjaEnv = scout_env.scoutJinjaEnv()
    commandDebug = scout_env.scoutEnv()
    apName = apName
    cmdTemplate = jinjaEnv.get_template("scout_change_ap_name")
    cmds = cmdTemplate.render(apName=apName, password=password)
    scoutCommands = cmds.splitlines()
    channel = scoutSsh.invoke_shell()
    print("INFO: Changing AP hostname on {}...".format(ip))
    for command in scoutCommands:
        channel.send('{}\n'.format(command))
        if commandDebug == "on":
            commands = channel.recv(65535)
            print(commands)
        time.sleep(.10)
    scoutSsh.close()
コード例 #18
0
def scoutEnableSnmp(ip, username, password, snmp):
    """Function that enables SNMP on AP."""
    scoutSsh = scout_auth.sshInfo(ip=ip, username=username, password=password)
    jinjaEnv = scout_env.scoutJinjaEnv()
    commandDebug = scout_env.scoutEnv()
    snmp = snmp
    cmdTemplate = jinjaEnv.get_template("scout_enable_ap_snmp")
    cmds = cmdTemplate.render(password=password, snmp=snmp)
    scoutCommands = cmds.splitlines()
    channel = scoutSsh.invoke_shell()
    print("INFO: Enabling SNMP server on {}...".format(ip))
    for command in scoutCommands:
        channel.send('{}\n'.format(command))
        if commandDebug == "on":
            commands = channel.recv(65535)
            print(commands)
        time.sleep(.10)
    scoutSsh.close()
コード例 #19
0
def scoutPing(ip, username, password):
    scoutSsh = scout_auth.sshInfo(ip=ip, username=username, password=password)
    jinjaEnv = scout_env.scoutJinjaEnv()
    cmdTemplate = jinjaEnv.get_template("scout_ssh_ping")
    cmds = cmdTemplate.render(password=password)
    scoutCommands = cmds.splitlines()
    channel = scoutSsh.invoke_shell()
    sshData = []
    for command in scoutCommands:
        channel.send('{}\n'.format(command))
        time.sleep(.75)
        if channel.recv_ready():
            sshReturn = channel.recv(65535)
            dataLines = sshReturn.decode('ascii')
            sshData.append(dataLines)
    scoutSsh.close()
    apPing = sshData[0].split("\n")[2:3]
    return apPing
コード例 #20
0
def scoutGetUsers(ip, username, password):
    """Function that retrieves AP users via show users."""
    scoutSsh = scout_auth.sshInfo(ip=ip, username=username, password=password)
    jinjaEnv = scout_env.scoutJinjaEnv()
    cmdTemplate = jinjaEnv.get_template("scout_get_users")
    cmds = cmdTemplate.render(password=password)
    scoutCommands = cmds.splitlines()
    channel = scoutSsh.invoke_shell()
    for command in scoutCommands:
        channel.send('{}\n'.format(command))
        time.sleep(.10)
    if channel.recv_ready():
        sshReturn = channel.recv(65535)
        userLines = sshReturn.splitlines()
        scoutSsh.close()
        getUsers = []
        for line in userLines[4:-1]:
            getUsers.append(line.decode('ascii').strip("\n"))
    return "\n".join(getUsers)
コード例 #21
0
def scoutTftpBackup(ip, username, password, tftpIp):
    """Function that performs TFTP backup of AP config."""
    scoutSsh = scout_auth.sshInfo(ip=ip, username=username, password=password)
    jinjaEnv = scout_env.scoutJinjaEnv()
    commandDebug = scout_env.scoutEnv()
    tftpIp = tftpIp
    cmdTemplate = jinjaEnv.get_template("scout_do_tftp_backup")
    cmds = cmdTemplate.render(password=password, tftpIp=tftpIp)
    scoutCommands = cmds.splitlines()
    channel = scoutSsh.invoke_shell()
    print("INFO: Generating TFTP backup for {0} and sending to {1}...".format(
        ip, tftpIp))
    for command in scoutCommands:
        channel.send('{}\n'.format(command))
        if commandDebug == "on":
            commands = channel.recv(65535)
            print(commands)
        time.sleep(.10)
    scoutSsh.close()
コード例 #22
0
def scoutFetcher(ip, username, password):
    """Function that fetches AP information over single SSH channel"""
    scoutSsh = scout_auth.sshInfo(ip=ip, username=username, password=password)
    jinjaEnv = scout_env.scoutJinjaEnv()
    cmdTemplate = jinjaEnv.get_template("scout_fetcher")
    cmds = cmdTemplate.render(password=password)
    scoutCommands = cmds.splitlines()
    channel = scoutSsh.invoke_shell()
    sshData = []
    apInfo = []
    for command in scoutCommands:
        channel.send('{}\n'.format(command))
        time.sleep(.75)
        if channel.recv_ready():
            sshReturn = channel.recv(65535)
            dataLines = sshReturn.decode('ascii')
            sshData.append(dataLines)
    scoutSsh.close()
    macAddrRegex = re.compile(r'\w\w\w\w.\w\w\w\w.\w\w\w\w')
    apModelRegex = re.compile(r'\w\w\w\-\w\w\w\w\w\w\w\w\-\w-\w\w')
    apSerialRegex = re.compile(r'\w\w\w\w\w\w\w\w\w\w\w')
    # Append info to apInfo[]
    apMacAddr = macAddrRegex.search(sshData[4].split(',')[1]).group(0)
    apInfo.append(apMacAddr)
    apBandwidth = sshData[3].split(",")[1]
    apInfo.append(apBandwidth)
    apIosInfo = sshData[5].replace("\r", '').split("\n")[1]
    apInfo.append(apIosInfo)
    apUptime = sshData[6].replace("\r", '').split("\n")[1]
    apInfo.append(apUptime)
    apSerial = apSerialRegex.search(sshData[7].split("\n")[2]).group(0)
    apInfo.append(apSerial)
    apModel = apModelRegex.search(sshData[7].split("\n")[2]).group(0)
    apInfo.append(apModel)
    calcClientCount = sshData[8].split('\n')[4:]
    apClientCount = len(macAddrRegex.findall(str(calcClientCount)))
    apInfo.append(apClientCount)
    apLocation = sshData[9].replace("\r", '').split("\n")[1]
    apInfo.append(apLocation)
    return apInfo
コード例 #23
0
def scoutDeleteSsid5(ip, username, password, ssid, vlan, radioSub, gigaSub):
    """Function that deletes an existing 5GHz SSID from an
    AP.
    """
    scoutSsh = scout_auth.sshInfo(ip=ip, username=username, password=password)
    jinjaEnv = scout_env.scoutJinjaEnv()
    commandDebug = scout_env.scoutEnv()
    ssid = ssid
    vlan = vlan
    radioSub = radioSub
    gigaSub = gigaSub
    cmdTemplate = jinjaEnv.get_template("scout_delete_ssid_5")
    cmds = cmdTemplate.render(password=password,ssid=ssid,vlan=vlan,radioSub=radioSub,gigaSub=gigaSub)
    scoutCommands = cmds.splitlines()
    channel = scoutSsh.invoke_shell()
    print("INFO: Removing 5GHz SSID {0} from {1}...".format(ssid,ip))
    for command in scoutCommands:
        channel.send('{}\n'.format(command))
        if commandDebug == "on":
            commands = channel.recv(65535)
            print(commands)
        time.sleep(.10)
    scoutSsh.close()