zabbix使用python爬虫批量获取主机信息

描述

zabbix无法批量筛选不可用的主机,所以写出python爬虫取相关信息,在桌面会生成一个txt,在excel导入以","分隔即可!

import requests,time,re,csv

headers={
    "Host":"monitor.xurikeji.com",
    "Referer":"https://monitor.xurikeji.com/zabbix.php?action=dashboard.view",
    "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0",
    "Cookie":"PHPSESSID=hstu9k7d28adbeqpl6bxyzd2o0; zbx_sessionid=8f281cd98165b093511e072212ds1025f2"
}

obj=re.compile(r'<tr><td><input.*?<a href=.*?>(?P<name>.*?)</a>.*?<a href="httpconf\.php.*?</td><td>(?P<ip>.*?)</td><td>(?P<proxy>.*?)</td><td>.*?class="status-container"><span class="(?P<status>.*?)"',re.S)

with open(r'D:\xuri-1.1\桌面\text.txt', 'a', encoding='UTF8') as f:
    for i in range(1,15):
        url="https://monitor.xurikeji.com/hosts.php?groupid=0&page="+str(i)
        response=requests.get(url,headers=headers)
        response.encoding = 'utf-8'
        source=response.text
        res=obj.finditer(source)
        for i in res:
            f.write(i.group('name')+","+i.group('ip')+","+i.group('proxy')+","+i.group('status')+"\n")
            print(i.group('name')+","+i.group('ip')+","+i.group('proxy'))

# coding:utf-8

import requests,time,re,csv

headers={
    "Host":"monitor.xurikeji.com",
    "Referer":"https://monitor.xurikeji.com/zabbix.php?action=dashboard.view",
    "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0",
    "Cookie":"PHPSESSID=k4a45anbtarqiuiojcrcobbki5; zbx_sessionid=2c620c08f46ec098e971a64f7759bcb6"
}

#obj=re.compile(r'<tr><td><input.*?<a href=.*?>(?P<name>.*?)</a>.*?<a href="httpconf\.php.*?</td><td>(?P<ip>.*?)</td><td>(?P<proxy>.*?)</td><td>.*?class="status-container"><span class="(?P<status>.*?)"',re.S)
obj=re.compile(r'<tr><td><input.*?<a href=.*?>(?P<name>.*?)</a>.*?<a href="httpconf\.php.*?</td><td>(?P<ip>.*?)</td><td>(?P<proxy>.*?)</td><td>.*?href="javascript:void\(0\)">(?P<startstop>.*?)</a></td>.*?<div class="status-container"><span class="(?P<status>.*?)">',re.S)


with open(r'C:\Users\xurikejio\Desktop\text.txt', 'a', encoding='UTF8') as f:
    # url = "https://monitor.xurikeji.com/hosts.php?groupid=0&page=1"
    # response = requests.get(url, headers=headers)
    # response.encoding = 'utf-8'
    # source = response.text
    # res=obj.finditer(source)
    # for i in res:
    #     #f.write(i.group('name')+","+i.group('ip')+","+i.group('proxy')+","+i.group('status')+"\n")
    #     print(i.group('name')+","+i.group('ip')+","+i.group('proxy')+","+i.group('startstop')+","+i.group('status'))
    for i in range(1,19):
        url="https://monitor.xurikeji.com/hosts.php?groupid=0&page="+str(i)
        response=requests.get(url,headers=headers)
        response.encoding = 'utf-8'
        source=response.text
        res=obj.finditer(source)
        for i in res:
            f.write(i.group('name')+","+i.group('ip')+","+i.group('proxy')+","+i.group('startstop')+","+i.group('status')+"\n")
            print(i.group('name')+","+i.group('ip')+","+i.group('proxy')+","+i.group('startstop')+","+i.group('status'))


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值