refactor get_vlans()
This commit is contained in:
parent
f10ceb07f1
commit
53216ad344
1 changed files with 2 additions and 34 deletions
36
main.py
36
main.py
|
@ -80,38 +80,10 @@ def get_cmd(host: str, xssid: str, cmd: int, **params) -> str:
|
|||
).text
|
||||
|
||||
|
||||
def get_vlans(response: str) -> dict:
|
||||
soup = BeautifulSoup(response, "html.parser")
|
||||
|
||||
data = {}
|
||||
table_body = soup.find("table", attrs={"width": "560"})
|
||||
|
||||
rows = table_body.find_all("tr")
|
||||
for row in rows[1:]:
|
||||
cols = row.find_all("td")
|
||||
cols = [ele.text.strip() for ele in cols]
|
||||
|
||||
try:
|
||||
_, vlan_id, vlan_name, vlan_type, _, _ = cols
|
||||
data.update(
|
||||
{
|
||||
vlan_id: {
|
||||
"name": vlan_name,
|
||||
"type": vlan_type,
|
||||
}
|
||||
}
|
||||
)
|
||||
except ValueError:
|
||||
continue
|
||||
|
||||
return data
|
||||
|
||||
|
||||
def parse_vlan_ports(response: str) -> dict:
|
||||
soup = BeautifulSoup(response, "html.parser")
|
||||
|
||||
data = {}
|
||||
# <input type="hidden" id="vlanMode_33" name="vlanMode_33" value="0">
|
||||
port_settings = soup.find_all(
|
||||
"input", attrs={"type": "hidden", "id": re.compile(r"vlanMode_\d+")}
|
||||
)
|
||||
|
@ -168,10 +140,6 @@ if __name__ == "__main__":
|
|||
|
||||
cookie = get_login_cookie(IP, "admin", os.environ.get("ADMIN_PW"))
|
||||
|
||||
print(dictify(extract_data_from_table(get_cmd(IP, cookie, 1283)), "VLAN ID"))
|
||||
print(dictify(extract_data_from_table(get_cmd(IP, cookie, 1290)), "Port"))
|
||||
print(parse_vlan_ports(get_cmd(IP, cookie, 1293, vid=2)))
|
||||
|
||||
# print(dictify(extract_data_from_table(get_cmd(IP, cookie, 1283)), "VLAN ID"))
|
||||
# print(dictify(extract_data_from_table(get_cmd(IP, cookie, 1290)), "Port"))
|
||||
|
||||
# vlans = get_vlans(get_cmd(IP, cookie, 1283))
|
||||
# print(vlans)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue