1 from bs4 import BeautifulSoup 2 import requests 3 import sys 4 5 class Zabbix(object): 6 def __init__(self, headers): 7 self.session = requests.Session() 8 self.headers = headers 9 def func(self): 10 headers={ 11 'Host':ip, 12 'Upgrade-Insecure-Requests':'1', 13 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36', 14 'cookie':'zbx_sessionid='+token 15 } 16 response=self.session.get(url='http://'+ip+port+'/zabbix/zabbix.php?action=report.status&ddreset=1',headers=headers,allow_redirects=False) 17 sourse = BeautifulSoup(response.text, 'html.parser') 18 text=sourse.find('span', {'class': 'green'}) 19 if not text : 20 text=sourse.find('span', {'class': 'red'}) 21 tq=text.string 22 print(tq) 23 if __name__ == '__main__': 24 ip=sys.argv[1] 25 if len(sys.argv)==3: 26 port='' 27 token=sys.argv[2] 28 elif len(sys.argv)==4: 29 port=':'+sys.argv[2] 30 token=sys.argv[3] 31 else: 32 exit() 33 headers = { 34 'Host': ip, 35 'Origin': ip, 36 'Referer':ip+'/zabbix/index.php', 37 'Upgrade-Insecure-Requests':'1', 38 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36', 39 } 40 status = Zabbix(headers=headers) 41 try: 42 status.func() 43 except Exception: 44 exit()