Skip to content
Snippets Groups Projects
Commit 4de4c0de authored by rick.mollard's avatar rick.mollard
Browse files
	modified:   README.txt
	deleted:    Untitled.ipynb
	deleted:    flipport-original.py
parents 2c4dd613 9393f858
No related branches found
No related tags found
No related merge requests found
......@@ -9,4 +9,8 @@ _________________________
1. Make sure you are in the correct folder where the file is located.
2. Update the text file for your Campus with the switches that you would like to work with.
3. type in "python3 flipport.py" to run the flipport.py script.
<<<<<<< HEAD
4. Enter your information and let the script run.
=======
4. Enter your information and let the script run.
>>>>>>> 9393f8584d3450a0989c88b14218a2ed1ef634c5
This diff is collapsed.
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 = Allow-Policy_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 = "Allow-Policy_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}}
#policyrole = "wired_l1_game_dur-3142-2"
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
def get_logs(self):
login = session.post(f"https://{self}/rest/v1/login", data=creds, verify=False)
#print(f"Login code from Switch: {login.status_code}")
# print(f"This is Cookie: {login.cookies}")
get_log = session.get(f"https://{self}/rest/v10.04/system/interfaces/{to2[0]}%2F{to2[1]}%2F{to2[2]}/port_access_clients?attributes=applied_role&depth=3")
print(get_log)
up_down = "down"
# we use json format get response payload
if policyrole in f"{get_log.json()}":
#print("Found!")
headers = {
'accept': '*/*',
'Content-Type': 'application/json',
}
data = f'{{"stp_config":{{"admin_edge_port_enable":true,"bpdu_guard_enable":true}},"user_config":{{"admin":"{up_down}"}},"aaa_auth_precedence": {{"1": "mac-auth","2": "dot1x"}},"aaa_auth_priority": {{"1": "dot1x","2": "mac-auth"}},"port_access_clients_limit": 15,"loop_protect_enable":true}}'
#data = f'{{"user_config":{{"admin":"{up_down}"}},"aaa_auth_priority": {{"1": "dot1x","2": "mac-auth"}},"port_access_clients_limit": 15,"loop_protect_enable":true}}'
#data = f'{"user_config": {"admin": "{up_down}"}}'
response = session.put(f'https://{self}/rest/v10.04/system/interfaces/{to2[0]}%2F{to2[1]}%2F{to2[2]}', headers=headers, data=data)
#print(response)
up_down = "up"
#data = f'{"user_config": {"admin": "up"}}'
data = f'{{"stp_config":{{"admin_edge_port_enable":true,"bpdu_guard_enable":true}},"user_config":{{"admin":"{up_down}"}},"aaa_auth_precedence": {{"1": "mac-auth","2": "dot1x"}},"aaa_auth_priority": {{"1": "dot1x","2": "mac-auth"}},"port_access_clients_limit": 15,"loop_protect_enable":true}}'
time.sleep(2)
response = session.put(f'https://{self}/rest/v10.04/system/interfaces/{to2[0]}%2F{to2[1]}%2F{to2[2]}', headers=headers, data=data)
else:
print("Not Found!")
headers = {
'accept': '*/*',
'Content-Type': 'application/json',
}
print("No port detected with role {policyrole} ")
logout = session.post(f"https://{self}/rest/v1/logout")
print(f"Logout Code from Switch:{logout.status_code}")
###############################################################################
output = net_connect.send_command(f"show port-access clients role {policyrole}")
to1 = output.split("\n")
#print(f"{to1}")
print(f"Ports that have role: {policyrole}:")
for to in to1 :
#to = to.lstrip()
#print(f"Now1: {to}")
to = to[2:]
#print(f"Now2: {to}")
to = to.split(" ")[0]
#print(f"Now3: {to}")
#output = net_connect.send_command(f"conf t")
#output = net_connect.send_command(f"interface {to}")
#output = net_connect.send_command(f"aaa authentication port-access auth-precedence mac-auth dot1x")
#output = net_connect.send_command(f"aaa authentication port-access auth-priority dot1x mac-auth")
#output = net_connect.send_command(f"aaa authentication port-access client-limit 15")
if re.search("[\d]+/[\d]/[\d]+",to):
print (to)
to2 = to.split("/")
#get_logs(ip_add)
#print (to2[0])
#print (to2[1])
#print (to2[2])
#print(net_connect.find_prompt())
net_connect.disconnect()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment