1 | # -*- coding: utf-8 -*- |
||
2 | # Copyright (C) 2017-2021 Greenbone Networks GmbH |
||
3 | # |
||
4 | # SPDX-License-Identifier: GPL-3.0-or-later |
||
5 | # |
||
6 | # This program is free software: you can redistribute it and/or modify |
||
7 | # it under the terms of the GNU General Public License as published by |
||
8 | # the Free Software Foundation, either version 3 of the License, or |
||
9 | # (at your option) any later version. |
||
10 | # |
||
11 | # This program is distributed in the hope that it will be useful, |
||
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
14 | # GNU General Public License for more details. |
||
15 | # |
||
16 | # You should have received a copy of the GNU General Public License |
||
17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
18 | |||
19 | import sys |
||
20 | |||
21 | |||
22 | def check_args(args): |
||
23 | len_args = len(args.script) - 1 |
||
24 | if len_args != 1: |
||
25 | message = """ |
||
26 | This script will display all hosts with the searched applications! |
||
27 | |||
28 | 1. <application> -- Name of the application |
||
29 | |||
30 | Example: |
||
31 | $ gvm-script --gmp-username name --gmp-password pass \ |
||
32 | ssh --hostname <gsm> scripts/application-detection.gmp.py <application> |
||
33 | """ |
||
34 | print(message) |
||
35 | sys.exit() |
||
36 | |||
37 | |||
38 | def print_assets(gmp, appname): |
||
39 | res = gmp.get_reports() |
||
40 | |||
41 | hosts = res.xpath('//host') |
||
42 | |||
43 | for host in hosts: |
||
44 | ip = host.xpath('ip/text()') |
||
45 | hostname = host.xpath('detail/name[text()="hostname"]/../value/text()') |
||
46 | if len(hostname) == 0: |
||
47 | hostname = "" |
||
48 | else: |
||
49 | hostname = hostname[0] |
||
50 | |||
51 | print('{ip} ({hostname})'.format(ip=ip, hostname=hostname)) |
||
52 | apps = host.xpath( |
||
53 | 'detail/name[text() = "App"]/../value[' |
||
54 | 'contains(text(), "{0}")]/text()'.format(appname) |
||
55 | ) |
||
56 | for app in apps: |
||
57 | print('\t' + app) |
||
58 | print('\n') |
||
59 | |||
60 | |||
61 | def main(gmp, args): |
||
62 | # pylint: disable=undefined-variable |
||
63 | |||
64 | check_args(args) |
||
65 | |||
66 | print_assets(gmp, args.script[1]) |
||
67 | |||
68 | |||
69 | if __name__ == '__gmp__': |
||
70 | main(gmp, args) |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
![]() Comprehensibility
Best Practice
introduced
by
|
|||
71 |