Skip to content
Snippets Groups Projects
Select Git revision
  • 601f3ea75e585eff80142a1929ee5ea09d0ba4d7
  • 3.9 default
  • develop
  • 6.0
  • 5.0
  • 4.0
  • scrutinizer-patch-4
  • scrutinizer-patch-3
  • scrutinizer-patch-2
  • scrutinizer-patch-1
  • 3.7
  • 3.8
  • 3.6
  • 3.9_backported
  • 3.8_backported
  • 3.7_backported
  • 3.5
  • 3.6_backported
  • 3.5_backported
  • 3.4
  • 3.3_backported
  • 6.0.4
  • 6.0.3
  • 5.0.7
  • 6.0.2
  • 6.0.1
  • 5.0.6
  • 6.0.0
  • 5.0.5
  • 6.0.0-rc
  • 5.0.4
  • 6.0.0-beta
  • 5.0.3
  • 4.0.6
  • 5.0.2
  • 5.0.1
  • 4.0.5
  • 5.0.0
  • 4.0.4
  • 5.0.0-rc2
  • 5.0.0-rc1
41 results

FilesLibTest.php

Blame
  • flipport.py 2.67 KiB
    from netmiko import ConnectHandler
    from getpass import getpass
    import requests
    import urllib3
    import re 
    import time
    import getpass
    
    urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
    
    ###########################################################################
    print(" 1 = UNL-City \n 2 = UNL-East \n 3 = UNO \n 4 = UNK \n Select Campus:")
    campus = input()
    print(f"Campus Selected: {campus}")
    print("----------------------------------")
    print("----------------------------------")
    print(" 1 = wired_l1_game_dur-3142-2 \n 2 = wired_l2_print_dur-3134-6 \n 3 = wired_ap_dur-3095-4 \n 4 = wired_l2_iot_dur-3147-2 \n 5 = wired_l2_shared_dur-3168-2 \n 6 = wired_cctv_dur-3107-8 \n 7 = test \n Select Role:")
    role = input()
    if campus == "1":
        file = [line.strip() for line in open("unlCitySwitches-cx.txt", 'r')]
    if campus == "2":
        file = [line.strip() for line in open("unlEastSwitches-cx.txt", 'r')]
    if campus == "3":
        file = [line.strip() for line in open("unoSwitches-cx.txt", 'r')]
    if campus == "4":
        file = [line.strip() for line in open("unkSwitches-cx.txt", 'r')]
        #print(file[])
        #file.close()
    
    if role == "1":
        policyrole = "wired_l1_game_dur-3142-2"
    if role == "2":
        policyrole = "wired_l2_print_dur-3134-6"
    if role == "3":
        policyrole = "wired_ap_dur-3095-4"
    if role == "4":
        policyrole = "wired_l2_iot_dur-3147-2"
    if role == "5":
        policyrole = "wired_l2_shared_dur-3168-2"
    if role == "6":
        policyrole = "wired_cctv_dur-3107-8"
    if role == "7":
        policyrole = "application-failed"
    ##########################################################################
    print("Enter Username:")
    Ausername = input()
    print("Enter Password:")
    Apassword = getpass.getpass()
    creds = {"username": {Ausername}, "password": {Apassword}}
    
    
    for selectIP in file:
        #print("Enter the Switch IP:")
        ip_add = selectIP
        print(ip_add)
        session = requests.session()
        
        net_connect = ConnectHandler(
        device_type="aruba_procurve",
        host=ip_add,
        username=Ausername,
        password=Apassword,
        )
    
    # create sessions object
        ###############################################################################
        output = net_connect.send_command(f"show port-access clients role {policyrole}")
        to1 = output.split("\n")
        print(f"Ports that have role: {policyrole}:")
    
        for to in to1 :
            to = to[2:]
            to = to.split(" ")[0]
    
            if re.search("[\d]+/[\d]/[\d]+",to):
                print (to)
                to2 = to.split("/")
                output2 = [f"interface {to2[0]}/{to2[1]}/{to2[2]}","shut","no shut"]
                net_connect.send_config_set(output2)
        net_connect.send_config_set(f"wr mem")
        net_connect.disconnect()
        print(f"Logged out from Switch!")