diff --git a/CampusSelector.py b/CampusSelector.py new file mode 100644 index 0000000000000000000000000000000000000000..2f6afa213d5610626de5a143e1f27517a8f4ecb2 --- /dev/null +++ b/CampusSelector.py @@ -0,0 +1,39 @@ +def Campus_Selector(): + print("Please select the switch scope: ") + print(" 1: City Campus \n 2: East Campus \n 3: Omaha \n 4: Kearney \n 5: Custom File \n 6: Single Switch") + ip = "0.0.0.0" + campus = "" + campus_selection = input() + if campus_selection == "1": + campus = "unlCitySwitches-cx.txt" + if campus_selection == "2": + campus = "unlEastSwitches-cx.txt" + if campus_selection == "3": + campus = "unoSwitches-cx.txt" + if campus_selection == "4": + campus = "unkSwitches-cx.txt" + if campus_selection == "5": + print("Type the name of your file:") + campus = input() + if campus_selection == "6": + print("Enter Switch IP Address:") + ip = input() + return campus, ip, campus_selection + + +def Role_Selector(): + print("What role would you like to reboot:") + print(" 1: CCTV \n 2: Doors \n 3: Printers \n 4: Failed Ports \n 5: Custom") + role = input() + if role == "1": + role = "wired_cctv_dur-3107-8" + if role == "2": + role = "wired_door_tunneled-3112-4" + if role == "3": + role = "wired_l2_print_dur-3134-6" + if role == "4": + role = "Fail" + if role == "5": + print("Please type your role:") + role = input() + return role diff --git a/ConfigChecker.py b/ConfigChecker.py new file mode 100644 index 0000000000000000000000000000000000000000..cb2d865d5b1460e415d3067884df139f48f36e53 --- /dev/null +++ b/ConfigChecker.py @@ -0,0 +1,168 @@ +from urllib3 import exceptions # Prevent SSL Self-Signed Certificate Error +import requests # Creation Of New Object +import urllib3 +from netmiko import (ConnectHandler,NetmikoTimeoutException) # SSH Connection +import socket # DNS Lookup +import time # For Waiting +import CampusSelector +import SwitchCommands + + +def main(ArubaUsername, ArubaPassword): + # Preparatory Work for SSH Connection + urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) # Disable Certificate Warning + interfaces = {} # Initialize the interface variable + current_interface = "" # Initialize Current Interface to make sure it isn't null + port_configuration = ['vlan access 1', 'enable', 'enable'] + exception = ['trunk allowed 2000', 'trunk allowed 1999'] + int_changes = [] + + # Get the Campus or Switch IP Address + campus = CampusSelector.Campus_Selector() + ip = campus[1] + campus_selection = campus[2] + campus_file = campus[0] + + # Single Switch Only + if campus_selection == "6": + hostname = socket.getfqdn(ip) + print('Current Switch:', hostname, ":", ip) + missing = [] + + # Create Session Object + #session = requests.session() + + # Create SSH Connection + + ssh = ConnectHandler( + device_type="aruba_procurve", + host=ip, + username=ArubaUsername, + password=ArubaPassword, + ) + + # Find The Ports With Deviations + try: + cli = ssh.send_command(f"show run int") + parse = cli.split("\n") + for line in parse: + for x in exception: + if x in line: + print("An Exception has been found, skipping port:", current_interface, + "Either exception VLAN or trunk port") + missing.clear() + continue + if line.split()[0].strip() == "interface": + if len(missing) > 0: + print("The following Config Was Missing From Interface:", current_interface, missing) + print( + "Would you like to reset this interface back to normal configuration? \n 1) Yes " + "\n 2) No") + missing.clear() + reset = input() + if reset == "1": # Reset the Interface + print('Resetting Port to Default: ', current_interface) + SwitchCommands.defaultport(ssh, current_interface) # Reset Port + int_changes.append(current_interface) + if reset == "2": # Skip Resetting the Interface + print("Skipping Interface Reset") + + # Set some Variables + current_interface = line.split()[1].strip() + port = current_interface.split("/")[-1] + + # Global Ignore Conditions + if port == '49' or port == '50' or port == '51' or port == '52': # Ignore SFP Ports + continue + if port == 'vlan1' or port == "vlan1999" or "lag" in port: # Ignore Local Interfaces + print("Local Interface, Skipping.", current_interface) + continue + for m in missing: + interfaces[current_interface].append(m) + for x in port_configuration: + missing.append(x) + else: + for command in missing: + if line.strip() == command.strip(): + missing.pop(missing.index(command.strip())) + + finally: + print("Logging Out From Switch", hostname, ip) + ssh.disconnect() + time.sleep(1) + + # Read from File + if campus_selection != "6": + with open(campus_file) as file: + while line := file.readline().rstrip(): + ip = line + hostname = socket.getfqdn(ip) + print('Current Switch:', hostname, ":", ip) + + missing = [] + # Create Session Object + session = requests.session() + + # Create SSH Connection + try: + ssh = ConnectHandler( + device_type="aruba_procurve", + host=ip, + username=ArubaUsername, + password=ArubaPassword, + ) + + # Find The Ports With Deviations + try: + cli = ssh.send_command(f"show run int") + parse = cli.split("\n") + for line in parse: + for x in exception: + if x in line or "trunk allowed" in line: + print("An Exception has been found, skipping port:", current_interface, "Either exception VLAN or trunk port") + missing.clear() + continue + if line.split()[0].strip() == "interface": + if len(missing) > 0: + print("The following Config Was Missing From Interface:", current_interface, missing) + print( + "Would you like to reset this interface back to normal configuration? \n 1) Yes " + "\n 2) No") + missing.clear() + reset = input() + if reset == "1": # Reset the Interface + print('Resetting Port to Default: ', current_interface) + SwitchCommands.defaultport(ssh, current_interface) # Reset Port + int_changes.append(current_interface) + if reset == "2": # Skip Resetting the Interface + print("Skipping Interface Reset") + + # Set some Variables + current_interface = line.split()[1].strip() + port = current_interface.split("/")[-1] + + # Global Ignore Conditions + if port == '49' or port == '50' or port == '51' or port == '52': # Ignore SFP Ports + continue + if port == 'vlan1' or port == "vlan1999" or "lag" in port: # Ignore Local Interfaces + print("Local Interface, Skipping.", current_interface) + continue + for m in missing: + interfaces[current_interface].append(m) + for x in port_configuration: + missing.append(x) + else: + for command in missing: + if line.strip() == command.strip(): + missing.pop(missing.index(command.strip())) + + finally: + print("Interfaces that changed:", int_changes) # Print Interface Change Summary + int_changes.clear() # Clear the List For Next Switch + print("Logging Out From Switch", hostname, ip) + ssh.disconnect() + time.sleep(1) + except (NetmikoTimeoutException) as error: + print("Switch is not responding-----> " + ip) + print("Switch is not responding-----> " + ip) + print("Switch is not responding-----> " + ip) diff --git a/SwitchCommands.py b/SwitchCommands.py new file mode 100644 index 0000000000000000000000000000000000000000..5fd4231baf087ec5713a9a6ea866bff2748e9d1f --- /dev/null +++ b/SwitchCommands.py @@ -0,0 +1,32 @@ +import netmiko +import ConfigChecker +import time + + +# File to hold switch commands + +def defaultport(ssh, current_interface): + interface_configuration = [f'interface {current_interface}', 'shutdown' + 'no routing', + 'vlan access 1', 'spanning-tree bpdu-guard', + 'spanning-tree port-type admin-edge', + 'aaa authentication port-access auth-precedence mac-auth dot1x', + 'aaa authentication port-access auth-priority dot1x mac-auth', + 'aaa authentication port-access client-limit 15', + 'aaa authentication port-access dot1x authenticator max-eapol-requests 1', + 'aaa authentication port-access dot1x authenticator max-retries 3', + 'aaa authentication port-access dot1x authenticator enable', + 'aaa authentication port-access mac-auth enable', + 'loop-protect', 'no shutdown'] + ssh.send_config_set(interface_configuration) # Send the Command To Reset The Interface + print("Interface:", current_interface, "has been reset.") + + +def shutport(ssh, current_interface): + interface_configuration = [f'interface {current_interface}', 'shut'] + ssh.send_config_set(interface_configuration) # Send a Shutdown Command + + +def noshutport(ssh, current_interface): + interface_configuration = [f'interface {current_interface}', 'no shut'] + ssh.send_config_set(interface_configuration) # Send a No Shutdown Command diff --git a/__pycache__/CampusSelector.cpython-310.pyc b/__pycache__/CampusSelector.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e52340b7c7ac5042170d0be72db8257947aef46a Binary files /dev/null and b/__pycache__/CampusSelector.cpython-310.pyc differ diff --git a/__pycache__/ConfigChecker.cpython-310.pyc b/__pycache__/ConfigChecker.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1240ce09b6eef00aad0cf6f4e855fe67c2bb4069 Binary files /dev/null and b/__pycache__/ConfigChecker.cpython-310.pyc differ diff --git a/__pycache__/FindLinkTransitions.cpython-310.pyc b/__pycache__/FindLinkTransitions.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ce4d417ab65ab047d4157e00a93ea8478adaeb1a Binary files /dev/null and b/__pycache__/FindLinkTransitions.cpython-310.pyc differ diff --git a/__pycache__/PortFlipper.cpython-310.pyc b/__pycache__/PortFlipper.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..af9bb1f73413539ce4009f8994e9432278edd557 Binary files /dev/null and b/__pycache__/PortFlipper.cpython-310.pyc differ diff --git a/__pycache__/SwitchCommands.cpython-310.pyc b/__pycache__/SwitchCommands.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ba2ac58f9170a3306e2f741939cb8b63eea82856 Binary files /dev/null and b/__pycache__/SwitchCommands.cpython-310.pyc differ diff --git a/findfails.py b/findfails.py index d5f327045a2d4ef2d2fe4a75d9d112f8895a227b..02b291e5768d79bc0dc721d1ceacddb3476bb724 100644 --- a/findfails.py +++ b/findfails.py @@ -14,7 +14,7 @@ urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) # ########################################################################### -print(" 1 = UNL-City \n 2 = UNL-East \n 3 = UNO \n 4 = UNK \n Select Campus:") +print(" 1 = UNL-City \n 2 = UNL-East \n 3 = UNO \n 4 = UNK \n 5 = Greater NE \n Select Campus:") campus = input() print(f"Campus Selected: {campus}") print("----------------------------------") @@ -29,6 +29,8 @@ 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')] +if campus == "5": + file = [line.strip() for line in open("greaterNebraska.txt", 'r')] #print(file[]) #file.close() @@ -65,6 +67,7 @@ for selectIP in file: if policyrole in to: print(to) to3 = to.split(" ")[0] + output3 = net_connect.send_command(f"aruba-central support-mode") output2 = net_connect.send_command(f"port-access reauthenticate interface {to3}") print(f"{to3} Reauthentication initiated.") diff --git a/greaterNebraska.txt b/greaterNebraska.txt new file mode 100644 index 0000000000000000000000000000000000000000..4951d1b72e250cd98e8aa31dac9467d6adefdf8b --- /dev/null +++ b/greaterNebraska.txt @@ -0,0 +1,2 @@ +10.162.139.1 +10.162.139.2 \ No newline at end of file diff --git a/highTransitions.py b/highTransitions.py index 480017a48cb06d431d437b5532196387dcd6c97c..a237b5dfcc47e725625555ce4b69f4874d3e97b7 100644 --- a/highTransitions.py +++ b/highTransitions.py @@ -47,7 +47,7 @@ for selectIP in file: try: # Login to API and set initial Variables login = session.post(f"https://{self}/rest/v1/login", data=creds, verify=False) - transitions = 10000 + transitions = 5000 vsfMember = 1 Switch = 1 SwitchPort = 1 diff --git a/highTransitions.txt b/highTransitions.txt new file mode 100644 index 0000000000000000000000000000000000000000..ca4a80aa9d099bc360e9bfc541c73f98ceb9d143 --- /dev/null +++ b/highTransitions.txt @@ -0,0 +1,15 @@ +Login from: kmsab00m1s1a01.nebraska.edu 10.171.0.10 +Port: 2/1/41 6845 +Logout from: kmsab00m1s1a01.nebraska.edu 10.171.0.10 +Login from: kcpst0310s1a01.nebraska.edu 10.171.0.12 +Logout from: kcpst0310s1a01.nebraska.edu 10.171.0.12 +Login from: k0fac0002s1a01.nebraska.edu 10.171.0.15 +Logout from: k0fac0002s1a01.nebraska.edu 10.171.0.15 +Login from: k0gsb0002s1a01.nebraska.edu 10.171.0.16 +Logout from: k0gsb0002s1a01.nebraska.edu 10.171.0.16 +Login from: klibr0028s1a01.nebraska.edu 10.171.0.19 +Logout from: klibr0028s1a01.nebraska.edu 10.171.0.19 +Login from: kthmh0001s1a01.nebraska.edu 10.171.0.20 +Port: 1/1/48 7251 +Port: 2/1/3 7283 +Logout from: kthmh0001s1a01.nebraska.edu 10.171.0.20 diff --git a/main.py b/main.py new file mode 100644 index 0000000000000000000000000000000000000000..ab3ff2394ed5c0eb99938fdc7614c026b92c5b75 --- /dev/null +++ b/main.py @@ -0,0 +1,39 @@ +# Primary Network Script For University of Nebraska +import ConfigChecker +import PortFlipper # PortFlipper Script +import FindLinkTransitions +import getpass # Password Handler + +# Get User Information +print("Please enter your NUID:") +ArubaUsername = input() +print("Please enter your password:") +ArubaPassword = getpass.getpass() + +# Get Choice +print("Please Select From the Following Choices: \n 1: Port Flipper \n 2: Configuration Checker 48 Port " + "\n 3: Configuration Checker 24 Port \n 4: Link Transitions") +selection = input() + +# Call The Port Flipper Script +if selection == '1': + PortFlipper.main(ArubaUsername, ArubaPassword) +# Call the VLAN Flipper Script +if selection == '2': + ConfigChecker.main(ArubaUsername, ArubaPassword) +# Call The MAC Address Flipper +if selection == '3': + print("Not Implemented Yet, on ToDo List") + # Idea behind this is if a specific device on the network needs re-authenticated, it will find the device and flip + # the port. +if selection == '4': + print("Find Excecive Link Transitions") + FindLinkTransitions.main(ArubaUsername, ArubaPassword) + + +# Sample code for personal reference +# def print_hi(name): +# print(f'Hi, {name}') + +# if __name__ == '__main__': +# print_hi('PyCharm') diff --git a/unkSwitches-cx.txt b/unkSwitches-cx.txt index 242c5937a668511ca15f78c2891df3cc54823dc5..a4f7d5cb662de53aa677b84c63ac504fc6fc3129 100644 --- a/unkSwitches-cx.txt +++ b/unkSwitches-cx.txt @@ -1,2 +1,65 @@ +10.171.0.10 +10.171.0.12 +10.171.0.15 +10.171.0.16 +10.171.0.19 +10.171.0.20 +10.171.0.21 +10.171.0.23 +10.171.0.24 +10.171.0.26 +10.171.0.27 +10.171.0.28 +10.171.0.29 +10.171.0.30 +10.171.0.31 +10.171.0.32 +10.171.0.33 +10.171.0.34 +10.171.0.35 +10.171.0.37 +10.171.0.38 +10.171.0.39 +10.171.0.40 +10.171.0.41 +10.171.0.42 +10.171.0.43 +10.171.0.44 +10.171.0.45 +10.171.0.47 +10.171.0.48 +10.171.0.49 +10.171.0.50 +10.171.0.51 +10.171.0.52 10.171.0.53 -10.171.0.28 \ No newline at end of file +10.171.0.54 +10.171.0.55 +10.171.0.56 +10.171.0.57 +10.171.0.58 +10.171.0.59 +10.171.0.60 +10.171.0.61 +10.171.0.62 +10.171.0.63 +10.171.0.64 +10.171.0.65 +10.171.0.66 +10.171.0.67 +10.171.0.68 +10.171.0.69 +10.171.0.70 +10.171.0.71 +10.171.0.72 +10.171.0.73 +10.171.0.74 +10.171.0.11 +10.171.0.13 +10.171.0.14 +10.171.0.17 +10.171.0.18 +10.171.0.25 +10.171.0.36 +10.171.0.46 +10.171.0.75 \ No newline at end of file diff --git a/unlCitySwitches-cx.txt b/unlCitySwitches-cx.txt new file mode 100644 index 0000000000000000000000000000000000000000..ca5887fc8788279e47564f1c0b7b9b42f5ac79cd --- /dev/null +++ b/unlCitySwitches-cx.txt @@ -0,0 +1,50 @@ +10.163.0.1 +10.163.0.2 +10.163.0.3 +10.163.0.4 +10.163.0.5 +10.163.0.6 +10.163.0.7 +10.163.0.8 +10.163.0.9 +10.163.0.10 +10.163.0.11 +10.163.0.12 +10.163.0.13 +10.163.0.14 +10.163.0.15 +10.163.0.16 +10.163.0.17 +10.163.0.18 +10.163.0.19 +10.163.0.20 +10.163.0.21 +10.163.0.22 +10.163.0.23 +10.163.0.24 +10.163.0.25 +10.163.0.26 +10.163.0.27 +10.163.0.28 +10.163.0.29 +10.163.0.30 +10.163.0.31 +10.163.0.32 +10.163.0.33 +10.163.0.34 +10.163.0.35 +10.163.0.36 +10.163.0.37 +10.163.0.38 +10.163.0.39 +10.163.0.40 +10.163.0.41 +10.163.0.42 +10.163.0.43 +10.163.0.44 +10.163.0.45 +10.163.0.46 +10.163.0.47 +10.163.0.48 +10.163.0.49 +10.163.0.50 \ No newline at end of file diff --git a/unoSwitches-cx.txt b/unoSwitches-cx.txt new file mode 100644 index 0000000000000000000000000000000000000000..65ed43cc0adf9e4b1ce593d27c4309c0409a027e --- /dev/null +++ b/unoSwitches-cx.txt @@ -0,0 +1,180 @@ +10.175.0.1 +10.175.0.2 +10.175.0.3 +10.175.0.4 +10.175.0.5 +10.175.0.6 +10.175.0.7 +10.175.0.8 +10.175.0.9 +10.175.0.10 +10.175.0.11 +10.175.0.12 +10.175.0.13 +10.175.0.14 +10.175.0.15 +10.175.0.16 +10.175.0.17 +10.175.0.18 +10.175.0.19 +10.175.0.20 +10.175.0.21 +10.175.0.22 +10.175.0.23 +10.175.0.24 +10.175.0.25 +10.175.0.26 +10.175.0.27 +10.175.0.28 +10.175.0.29 +10.175.0.30 +10.175.0.31 +10.175.0.32 +10.175.0.33 +10.175.0.34 +10.175.0.35 +10.175.0.36 +10.175.0.37 +10.175.0.38 +10.175.0.39 +10.175.0.40 +10.175.0.41 +10.175.0.42 +10.175.0.43 +10.175.0.44 +10.175.0.45 +10.175.0.46 +10.175.0.47 +10.175.0.48 +10.175.0.49 +10.175.0.50 +10.175.0.51 +10.175.0.52 +10.175.0.53 +10.175.0.54 +10.175.0.55 +10.175.0.56 +10.175.0.57 +10.175.0.58 +10.175.0.59 +10.175.0.60 +10.175.0.61 +10.175.0.62 +10.175.0.63 +10.175.0.64 +10.175.0.65 +10.175.0.66 +10.175.0.67 +10.175.0.68 +10.175.0.69 +10.175.0.70 +10.175.0.71 +10.175.0.72 +10.175.0.73 +10.175.0.74 +10.175.0.75 +10.175.0.76 +10.175.0.77 +10.175.0.78 +10.175.0.79 +10.175.0.80 +10.175.0.81 +10.175.0.82 +10.175.0.83 +10.175.0.84 +10.175.0.85 +10.175.0.86 +10.175.0.87 +10.175.0.88 +10.175.0.89 +10.175.0.90 +10.175.0.91 +10.175.0.92 +10.175.0.93 +10.175.0.94 +10.175.0.95 +10.175.0.96 +10.175.0.97 +10.175.0.98 +10.175.0.99 +10.175.0.100 +10.175.0.101 +10.175.0.102 +10.175.0.103 +10.175.0.104 +10.175.0.105 +10.175.0.106 +10.175.0.107 +10.175.0.108 +10.175.0.109 +10.175.0.110 +10.175.0.111 +10.175.0.112 +10.175.0.113 +10.175.0.114 +10.175.0.115 +10.175.0.116 +10.175.0.117 +10.175.0.118 +10.175.0.119 +10.175.0.120 +10.175.0.121 +10.175.0.122 +10.175.0.123 +10.175.0.124 +10.175.0.125 +10.175.0.126 +10.175.0.127 +10.175.0.128 +10.175.0.129 +10.175.0.130 +10.175.0.131 +10.175.0.132 +10.175.0.133 +10.175.0.134 +10.175.0.135 +10.175.0.136 +10.175.0.137 +10.175.0.138 +10.175.0.139 +10.175.0.140 +10.175.0.141 +10.175.0.142 +10.175.0.143 +10.175.0.144 +10.175.0.145 +10.175.0.146 +10.175.0.147 +10.175.0.148 +10.175.0.149 +10.175.0.150 +10.175.0.151 +10.175.0.152 +10.175.0.153 +10.175.0.154 +10.175.0.155 +10.175.0.156 +10.175.0.157 +10.175.0.158 +10.175.0.159 +10.175.0.160 +10.175.0.161 +10.175.0.162 +10.175.0.163 +10.175.0.164 +10.175.0.165 +10.175.0.166 +10.175.0.167 +10.175.0.168 +10.175.0.169 +10.175.0.170 +10.175.0.171 +10.175.0.172 +10.175.0.173 +10.175.0.174 +10.175.0.175 +10.175.0.176 +10.175.0.177 +10.175.0.178 +10.175.0.179 +10.175.0.180 \ No newline at end of file