1
+ #author:九世
2
+ #time:2019/4/14
3
+
4
+ import requests
5
+ from bs4 import BeautifulSoup
6
+ import asyncio
7
+ from aiohttp import ClientSession
8
+ import re
9
+ import xlwt
10
+ import time
11
+ import os
12
+
13
+ new_cve = []
14
+ bh_cve = []
15
+ jg_cve = []
16
+
17
+ class Demon :
18
+ def __init__ (self ,headers ,url ):
19
+ self .headers = headers
20
+ self .url = url
21
+
22
+ def zx (self ):
23
+ try :
24
+ rgt = requests .get (url = self .url ,headers = headers ,timeout = 3 )
25
+ zg = BeautifulSoup (rgt .text ,'html.parser' )
26
+ for c in zg .find_all ('a' ):
27
+ href = c .get ('href' )
28
+ new_cve .append (href )
29
+ except Exception as r :
30
+ print ('[-] Error {}' .format (r ))
31
+
32
+
33
+ async def zhuaqu (self ,url ):
34
+ async with ClientSession () as reqt :
35
+ try :
36
+ async with reqt .get (url = url ,headers = self .headers ,timeout = 2 ) as respone :
37
+ url = respone .url
38
+ jg_cve .append (url )
39
+ zz = re .findall ('[0-9]{1,}-.*' ,str (url ))
40
+ bh_cve .append ('CVE-{}' .format (zz [0 ]))
41
+
42
+ except :
43
+ pass
44
+
45
+ def writes (self ):
46
+ workbook = xlwt .Workbook (encoding = 'utf-8' )
47
+ sheet = workbook .add_sheet ("今天更新的CVE" )
48
+ sheet .write (0 ,0 ,"CVE编号" )
49
+ sheet .write (0 ,1 ,"URL" )
50
+ for i in range (0 ,len (bh_cve )):
51
+ sheet .write (int (i )+ 1 ,0 ,bh_cve [i ])
52
+ sheet .write (int (i )+ 1 ,1 ,'{}' .format (jg_cve [i ]))
53
+
54
+ sz = time .time ()
55
+ workbook .save ('{}.xls' .format (sz ))
56
+ if os .path .exists ('{}.xls' .format (sz )):
57
+ print ('[+] 保存成功' )
58
+ else :
59
+ print ('[-] 保存失败' )
60
+
61
+ async def main (self ):
62
+ td = []
63
+ for n in new_cve :
64
+ jc = asyncio .ensure_future (self .zhuaqu (n ))
65
+ td .append (jc )
66
+
67
+ await asyncio .wait (td )
68
+
69
+
70
+ if __name__ == '__main__' :
71
+ headers = {'user-agent' :'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36' }
72
+ urls = 'https://cassandra.cerias.purdue.edu/CVE_changes/today.html'
73
+ obj = Demon (headers = headers ,url = urls )
74
+ obj .zx ()
75
+ loop = asyncio .get_event_loop ()
76
+ loop .run_until_complete (obj .main ())
77
+ loop .close ()
78
+ obj .writes ()
0 commit comments