-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkpoint.py
executable file
·58 lines (49 loc) · 2.15 KB
/
checkpoint.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import websocket
import json
from datetime import datetime
def getUTCTimestamp():
return datetime.utcnow()
def doDump():
prevDate = getUTCTimestamp().date()
f = open('checkpoint_dump_' + str(prevDate) + '.csv', 'a', 1)
ws = websocket.create_connection('wss://threatmap.checkpoint.com/ThreatPortal/websocket' +
'?X-Atmosphere-tracking-id=0' +
'&X-Atmosphere-Framework=2.2.5-javascript' +
'&X-Atmosphere-Transport=websocket' +
'&X-Atmosphere-TrackMessageSize=true' +
'&Content-Type=application/json' +
'&X-atmo-protocol=true')
count = 1
flag = 0
try:
while ws.connected:
try:
result = ws.recv()
if count > 1:
result = result.split('|')[1]
dump = json.loads(result)
timestamp = getUTCTimestamp()
# attack , source_lat , source_long , destination_lat , destination_long , timestamp (UTC)
data_string = (str(dump['attackname']) + ' , ' + str(dump['sourcelatitude']) + ' , ' +
str(dump['sourcelongitude']) + ' , ' + str(dump['destinationlatitude']) +
' , ' + str(dump['destinationlongitude']) + ' , ' + str(timestamp))
if timestamp.date() > prevDate:
f.close()
f = open('checkpoint_dump_' + str(timestamp.date()) + '.csv', 'a', 1)
prevDate = timestamp.date()
f.write(data_string + "\n")
print(data_string)
flag = 2
count = 2
except Exception as e:
flag = 1
pass
finally:
print('Closing file...')
f.close()
if __name__ == "__main__":
while True:
try:
doDump()
except:
pass