Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nmap inventory plugin, add use_arp_ping option #7119

Merged
merged 3 commits into from
Aug 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelogs/fragments/7118-nmap_inv_plugin_no_arp_option.yml
Original file line number Diff line number Diff line change
@@ -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).
36 changes: 22 additions & 14 deletions plugins/inventory/nmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@
type: boolean
default: false
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:
- 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'
Expand Down Expand Up @@ -196,40 +201,43 @@ def parse(self, inventory, loader, path, cache=True):
# setup command
cmd = [self._nmap]

if self._options['sudo']:
if self.get_option['sudo']:
cmd.insert(0, 'sudo')

if self._options['port']:
if self.get_option['port']:
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')

if self._options['ipv4'] and not self._options['ipv6']:
if self.get_option['ipv4'] and not self.get_option['ipv6']:
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')
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')

if self._options['exclude']:
if self.get_option['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')

if self._options['udp_scan']:
if self.get_option['udp_scan']:
cmd.append('-sU')

if self._options['icmp_timestamp']:
if self.get_option['icmp_timestamp']:
cmd.append('-PP')

if self._options['open']:
if self.get_option['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:
# execute
p = Popen(cmd, stdout=PIPE, stderr=PIPE)
Expand Down