|
1
|
|
|
"""The module describes the VirusTotalAPIAnalyses class |
|
2
|
|
|
|
|
3
|
|
|
Author: Evgeny Drobotun (c) 2019 |
|
4
|
|
|
License: MIT (https://github.com/drobotun/virustotalapi3/blob/master/LICENSE) |
|
5
|
|
|
|
|
6
|
|
|
More information: https://virustotalapi3.readthedocs.io/en/latest/analyses_class.html |
|
7
|
|
|
""" |
|
8
|
|
|
|
|
9
|
|
|
import errno |
|
10
|
|
|
import requests |
|
11
|
|
|
|
|
12
|
|
|
from .vtapi3base import VirusTotalAPI |
|
13
|
|
|
from .vtapi3error import VirusTotalAPIError |
|
14
|
|
|
|
|
15
|
|
|
class VirusTotalAPIAnalyses(VirusTotalAPI): |
|
16
|
|
|
"""The retrieving information about analysis of the file or URL method are defined in the class. |
|
17
|
|
|
|
|
18
|
|
|
Methods: |
|
19
|
|
|
get_report(): Retrieve information about a file or URL analysis. |
|
20
|
|
|
""" |
|
21
|
|
|
|
|
22
|
|
|
def get_report(self, object_id): |
|
23
|
|
|
"""Retrieve information about a file or URL analysis. |
|
24
|
|
|
|
|
25
|
|
|
Args: |
|
26
|
|
|
object_id: Analysis identifier (str). |
|
27
|
|
|
|
|
28
|
|
|
Return: |
|
29
|
|
|
The response from the server as a byte sequence. |
|
30
|
|
|
|
|
31
|
|
|
Exception |
|
32
|
|
|
VirusTotalAPIError(Connection error): In case of server connection errors. |
|
33
|
|
|
VirusTotalAPIError(Timeout error): If the response timeout from the server is exceeded. |
|
34
|
|
|
""" |
|
35
|
|
|
self._last_http_error = None |
|
36
|
|
|
self._last_result = None |
|
37
|
|
|
api_url = self.base_url + '/analyses/' + object_id |
|
38
|
|
|
try: |
|
39
|
|
|
response = requests.get(api_url, headers=self.headers, |
|
40
|
|
|
timeout=self.timeout, proxies=self.proxies) |
|
41
|
|
|
except requests.exceptions.Timeout: |
|
42
|
|
|
raise VirusTotalAPIError('Timeout error', errno.ETIMEDOUT) |
|
43
|
|
|
except requests.exceptions.ConnectionError: |
|
44
|
|
|
raise VirusTotalAPIError('Connection error', errno.ECONNABORTED) |
|
45
|
|
|
else: |
|
46
|
|
|
self._last_http_error = response.status_code |
|
47
|
|
|
self._last_result = response.content |
|
48
|
|
|
return response.content |
|
49
|
|
|
|