Conditions | 7 |
Total Lines | 29 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | #! /usr/bin/python |
||
11 | def run(self, rand, count, nameserver, hostname, queryopts): |
||
12 | opt_list = [] |
||
13 | output = [] |
||
14 | |||
15 | cmd_args = ['dig'] |
||
16 | if nameserver: |
||
17 | nameserver = '@' + nameserver |
||
18 | cmd_args.append(nameserver) |
||
19 | |||
20 | if re.search(',', queryopts): |
||
21 | opt_list = queryopts.split(',') |
||
22 | else: |
||
23 | opt_list.append(queryopts) |
||
24 | for k, v in enumerate(opt_list): |
||
25 | cmd_args.append('+' + v) |
||
26 | |||
27 | cmd_args.append(hostname) |
||
28 | result_list = filter(None, subprocess.Popen(cmd_args, |
||
29 | stderr=subprocess.PIPE, |
||
30 | stdout=subprocess.PIPE) |
||
31 | .communicate()[0] |
||
32 | .split('\n')) |
||
33 | if int(count) > len(result_list) or count <= 0: |
||
34 | count = len(result_list) |
||
35 | |||
36 | output = result_list[0:count] |
||
37 | if rand is True: |
||
38 | random.shuffle(output) |
||
39 | return output |
||
40 |