美文网首页
监测一些列网站能否正常反馈200状态码

监测一些列网站能否正常反馈200状态码

作者: 小王同学123321 | 来源:发表于2018-05-30 13:03 被阅读0次

首先将网站的url列表放在脚本同目录下的url.list中
脚本放在check_source.py
脚本内容如下

#!/usr/bin/env python
#-*- coding=utf-8 -*-

import sys
import os
import requests
import threading

headers = {'User-Agent' : 'Mozilla/5.0 '}
http_code = ''
mlock = threading.Lock()

def check_source(url):
    global http_code
    mlock.acquire()
    req = requests.get(url,headers = headers)
    http_code = req.status_code
    mlock.release()
    print http_code
    #state_information = "/opt/zabbix/bin/zabbix_sender -z 10.12.60.115 -s  check_source_health -k %s_sec -o %s" %(item,http_code)
    #os.system(state_information)

if __name__ == '__main__':
    threads = []
    with open('v2_url.list','r+') as url_f:
        urls = url_f.readlines()
        for url in urls:
            if url:
                url = url.strip("\n")
                t = threading.Thread(target=check_source,args=[url])
                t.start()
                threads.append(t)
    
    for t in threads:
        t.join()

这个脚本只是实现标题的一种方式,使用的是requests,还有使用其他的模块urllib,pycurl。甚至使用使用shell命令

相关文章

网友评论

      本文标题:监测一些列网站能否正常反馈200状态码

      本文链接:https://www.haomeiwen.com/subject/mzmtsftx.html