Select Git revision
findfails.py
rick.mollard authored
findfails.py 2.05 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 = 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 = "Fail"
##########################################################################
print("Enter Username:")
Ausername = input()
print("Enter Password:")
Apassword = getpass.getpass()
creds = {"username": {Ausername}, "password": {Apassword}}
for selectIP in file:
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")
to1 = output.split("\n")
print(f"Ports that have role: {policyrole}:")
for to in to1 :
to = to.lstrip()
#print(to)
if policyrole in to:
print(to)
to3 = to.split(" ")[0]
output2 = net_connect.send_command(f"port-access reauthenticate interface {to3}")
print(f"{to3} Reauthentication initiated.")
to = to.split(" ")[0]
net_connect.disconnect()