1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

nmap inventory plugin, add use_arp_ping option (#7119)

* nmap inventory plugin, add use_arp_ping option

* Apply suggestions from code review

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/inventory/nmap.py

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
Brian Coca 2023-08-20 08:21:51 -04:00 committed by GitHub
parent 33998a5b70
commit eaf3926c2c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 14 deletions

View file

@ -0,0 +1,4 @@
minor_changes:
- nmap inventory plugin - now has a ``use_arp_ping`` option to allow the user to disable the default ARP ping query for a more reliable form (https://github.com/ansible-collections/community.general/pull/7119).
bugfixes:
- nmap inventory plugin - now uses ``get_option`` in all cases to get its configuration information (https://github.com/ansible-collections/community.general/pull/7119).

View file

@ -85,6 +85,11 @@ DOCUMENTATION = '''
type: boolean type: boolean
default: false default: false
version_added: 6.1.0 version_added: 6.1.0
use_arp_ping:
description: Whether to always (V(true)) use the quick ARP ping or (V(false)) a slower but more reliable method.
type: boolean
default: true
version_added: 7.4.0
notes: notes:
- At least one of ipv4 or ipv6 is required to be True, both can be True, but they cannot both be False. - At least one of ipv4 or ipv6 is required to be True, both can be True, but they cannot both be False.
- 'TODO: add OS fingerprinting' - 'TODO: add OS fingerprinting'
@ -196,40 +201,43 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
# setup command # setup command
cmd = [self._nmap] cmd = [self._nmap]
if self._options['sudo']: if self.get_option['sudo']:
cmd.insert(0, 'sudo') cmd.insert(0, 'sudo')
if self._options['port']: if self.get_option['port']:
cmd.append('-p') cmd.append('-p')
cmd.append(self._options['port']) cmd.append(self.get_option['port'])
if not self._options['ports']: if not self.get_option['ports']:
cmd.append('-sP') cmd.append('-sP')
if self._options['ipv4'] and not self._options['ipv6']: if self.get_option['ipv4'] and not self.get_option['ipv6']:
cmd.append('-4') cmd.append('-4')
elif self._options['ipv6'] and not self._options['ipv4']: elif self.get_option['ipv6'] and not self.get_option['ipv4']:
cmd.append('-6') cmd.append('-6')
elif not self._options['ipv6'] and not self._options['ipv4']: elif not self.get_option['ipv6'] and not self.get_option['ipv4']:
raise AnsibleParserError('One of ipv4 or ipv6 must be enabled for this plugin') raise AnsibleParserError('One of ipv4 or ipv6 must be enabled for this plugin')
if self._options['exclude']: if self.get_option['exclude']:
cmd.append('--exclude') cmd.append('--exclude')
cmd.append(','.join(self._options['exclude'])) cmd.append(','.join(self.get_option['exclude']))
if self._options['dns_resolve']: if self.get_option['dns_resolve']:
cmd.append('-n') cmd.append('-n')
if self._options['udp_scan']: if self.get_option['udp_scan']:
cmd.append('-sU') cmd.append('-sU')
if self._options['icmp_timestamp']: if self.get_option['icmp_timestamp']:
cmd.append('-PP') cmd.append('-PP')
if self._options['open']: if self.get_option['open']:
cmd.append('--open') cmd.append('--open')
cmd.append(self._options['address']) if not self.get_option['use_arp_ping']:
cmd.append('--disable-arp-ping')
cmd.append(self.get_option['address'])
try: try:
# execute # execute
p = Popen(cmd, stdout=PIPE, stderr=PIPE) p = Popen(cmd, stdout=PIPE, stderr=PIPE)