· 8 years ago · Jan 26, 2018, 02:50 AM
1import os
2from datetime import datetime, date, timedelta
3import subprocess
4import pyjq
5import pandas as pd
6import sys
7import csv
8
9# Initializes the variables for the directories
10HomeDir = "/Users/kiya/Downloads/"
11ScriptDir = HomeDir + "/panpython"
12ResultDir = "/Users/kiya/Desktop/result"
13
14# Create the dates
15ToDay = datetime.now().strftime('%Y%m%d')
16# checkDATE = (date.today() - timedelta(1)).strfttime('%Y%m%d')
17ResultFile = "Test"
18CheckDATE = "2015-10-01"
19NOWDATE = "2015-10-02"
20
21secretkey = 'secret key'
22
23progToRun = 'python ' + ScriptDir + '/bin/panafapi.py -K ' + secretkey + ' --samples -j -r "{\\"query\\":{\\"operator\\":\\"all\\",\\"children\\":[{\\"field\\":\\"alias.ip_address\\",\\"operator\\":\\"contains\\",\\"value\\":\\"' + ResultFile + '\\"},{\\"operator\\":\\"any\\",\\"children\\":[{\\"field\\":\\"sample.update_date\\",\\"operator\\":\\"is in the range\\",\\"value\\":[\\"' + CheckDATE + 'T00:00:00\\",\\"' + NOWDATE + 'T23:59:59\\"]},{\\"field\\":\\"sample.create_date\\",\\"operator\\":\\"is in the range\\",\\"value\\":[\\"' + CheckDATE + 'T00:00:00\\",\\"' + NOWDATE + 'T23:59:59\\"]},{\\"operator\\":\\"any\\",\\"children\\":[{\\"field\\":\\"sample.malware\\",\\"operator\\":\\"is\\",\\"value\\":1},{\\"field\\":\\"sample.malware\\",\\"operator\\":\\"is\\",\\"value\\":4}]}]}]},\\"scope\\":\\"global\\",\\"size\\":1,\\"from\\":0,\\"sort\\":{\\"create_date\\":{\\"order\\":\\"desc\\"}}}" > ' + ResultDir + 'srciplist-' + ToDay + '.json'
24
25# Run the panafpi
26subprocess.check_output(progToRun, shell=True)
27
28# Using pyjq to filter
29filteredResultData = pyjq.all('.hits[]._source | .create_date + "," + .sha256')
30
31
32# Save the JSON file to comma-separated file
33pd.to_csv(ResultDir + "/srciplist-" + ToDay + ".csv", sep=",")
34
35
36
37samples_results: 200 OK 80% hits=1 total=544092 time=0:06:14.227
38samples_results: 200 OK 80% hits=1 total=544092 time=0:06:14.227
39samples_results: 200 OK 80% hits=1 total=544092 time=0:06:14.227
40samples_results: 200 OK 80% hits=1 total=544092 time=0:06:14.227
41samples_results: 200 OK 87% hits=1 total=585376 time=0:07:04.481
42samples_results: 200 OK 95% hits=1 total=657487 time=0:07:18.785
43samples_results: 200 OK 99% hits=1 total=674116 time=0:07:22.340
44samples_results: 200 OK 99% hits=1 total=674116 time=0:07:22.340
45samples_results: 200 OK 99% hits=1 total=674116 time=0:07:22.340
46samples_results: 200 OK 99% hits=1 total=674116 time=0:07:22.340
47samples_results: 200 OK 100% hits=1 total=674375 time=0:08:21.623 "complete"
48Traceback (most recent call last):
49 File "/Users/kiya/PycharmProjects/implace/finalauto.py", line 33, in <module>
50 pd.to_csv(ResultDir + "/srciplist-" + ToDay + ".csv", sep=",")
51AttributeError: module 'pandas' has no attribute 'to_csv'
52
53Process finished with exit code 1