首先将网站的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命令
网友评论