home-assistant.io/source/_components/nmap_tracker.markdown
Franck Nijhof c464056402
Making our website faster, cleaner and prettier (#9853)
* 🔥 Removes octopress.js

* 🔥 Removes use of root_url var

* 🔥 Removes Octopress generator reference from feed

* 🔥 Removes delicious support

* 🔥 Removes support for Pinboard

* 🔥 Removes support for Disqus

* 🔥 Removes support for Google Plus

* ↩️ Migrate custom after_footer to default template

* ↩️ Migrate custom footer to default template

* ↩️ Migrate custom header to default template

* 🔥 Removes unused template files

* 🚀 Places time to read directly in post template

* 🚀 Removes unneeded capture from archive_post.html template

* 🔥 🚀 Removes unused, but heaving sorting call in component page

* 🚀 Merged javascripts into a single file

* 🔥 Removes more uses of root_url

* 🚀 Removal of unneeded captures from head

* 🔥 🚀 Removal of expensive liquid HTML compressor

* 🔥 Removes unneeded templates

* 🚀 Replaces kramdown with GitHub's CommonMark 🚀

* 💄 Adds Prism code syntax highlighting

*  Adds support for redirect in Netlify

* ↩️ 🔥 Let Netlify handle all developer doc redirects

* ✏️ Fixes typo in redirects file: Netify -> Netlify

* 🔥 Removes unused .themes folder

* 🔥 Removes unused aside.html template

* 🔥 Removes Disqus config leftover

* 🔥 Removes rouge highlighter config

* 🔥 Removes Octopress 🎉

* 💄 Adjust code block font size and adds soft wraps

* 💄 Adds styling for inline code blocks

* 💄 Improve styling of note/warning/info boxes + div support

* 🔨 Rewrites all note/warning/info boxes
2019-07-15 22:17:54 +02:00

3.4 KiB

title, description, logo, ha_category, ha_release, redirect_from
title description logo ha_category ha_release redirect_from
Nmap Instructions on how to integrate Nmap into Home Assistant. nmap.png
Presence Detection
0.7
/components/device_tracker.nmap_tracker/

As an alternative to the router-based device tracking, it is possible to directly scan the network for devices by using Nmap. The IP addresses to scan can be specified in any format that Nmap understands, including the network-prefix notation (192.168.1.1/24) and the range notation (192.168.1.1-255).

Please keep in mind that modern smart phones will usually turn off WiFi when they are idle. Simple trackers like this may not be reliable on their own.

You might have to install the packages for arp and nmap. On Debian based hosts (for example Hassbian and Raspbian) do so by running $ sudo apt-get install net-tools nmap. On a Fedora host run $ sudo dnf -y install nmap.

If you are using Hass.io then just move forward to the configuration as all requirements are already fulfilled.

Host detection is done via Nmap's "fast scan" (-F) of the most frequently used 100 ports, with a host timeout of 5 seconds.

To use this device tracker in your installation, add the following to your configuration.yaml file:

# Example configuration.yaml entry
device_tracker:
  - platform: nmap_tracker
    hosts: 192.168.1.0/24

{% configuration %} hosts: description: The network address to scan (in any supported Nmap format). Mixing subnets and IPs is possible. required: true type: string home_interval: description: The number of minutes Nmap will not scan this device, assuming it is home, in order to preserve the device battery. required: false type: integer exclude: description: Hosts not to include in Nmap scanning. Scanning the host where Home Assistant is running can cause problems (websocket error and authentication failures), so excluding that host is a good idea. required: false type: list scan_options: description: Configurable scan options for Nmap. required: false default: -F --host-timeout 5s type: string {% endconfiguration %}

Examples

A full example for the nmap tracker could look like the following sample:

# Example configuration.yaml entry for Nmap
# One whole subnet, and skipping two specific IPs.
device_tracker:
  - platform: nmap_tracker
    hosts: 192.168.1.0/24
    home_interval: 10
    exclude:
     - 192.168.1.12
     - 192.168.1.13
# Example configuration.yaml for Nmap
# One subnet, and two specific IPs in another subnet.
device_tracker:
  - platform: nmap_tracker
    hosts:
      - 192.168.1.0/24
      - 10.0.0.2
      - 10.0.0.15

In the above example, Nmap will be call with the process: nmap -oX - 192.168.1.1/24 10.0.0.2 10.0.0.15 -F --host-timeout 5s

An example of how the Nmap scanner can be customized:

Linux capabilities

On Linux systems (such as Hass.io) you can extend the functionality of Nmap, without having to run it as root, by using Linux capabilities. Be sure to specify the full path to wherever you installed Nmap:

$ sudo setcap cap_net_raw,cap_net_admin,cap_net_bind_service+eip /usr/bin/nmap

And you can set up the device tracker as

- platform: nmap_tracker
  hosts: 192.168.1.1-25
  scan_options: " --privileged -sP "

See the device tracker integration page for instructions how to configure the people to be tracked.