From f5b010c15c0391cee190a69b4815169106a9f57a Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sat, 11 Jan 2020 18:51:54 +0100 Subject: [PATCH] Added nmap integration (closes #99) --- docs/source/platypush/plugins/nmap.rst | 5 +++++ docs/source/plugins.rst | 1 + platypush/plugins/nmap.py | 30 ++++++++++++++++++++++++++ requirements.txt | 3 +++ setup.py | 2 ++ 5 files changed, 41 insertions(+) create mode 100644 docs/source/platypush/plugins/nmap.rst create mode 100644 platypush/plugins/nmap.py diff --git a/docs/source/platypush/plugins/nmap.rst b/docs/source/platypush/plugins/nmap.rst new file mode 100644 index 000000000..4067f3b64 --- /dev/null +++ b/docs/source/platypush/plugins/nmap.rst @@ -0,0 +1,5 @@ +``platypush.plugins.nmap`` +========================== + +.. automodule:: platypush.plugins.nmap + :members: diff --git a/docs/source/plugins.rst b/docs/source/plugins.rst index 686b3cc97..585d009ba 100644 --- a/docs/source/plugins.rst +++ b/docs/source/plugins.rst @@ -78,6 +78,7 @@ Plugins platypush/plugins/music.rst platypush/plugins/music.mpd.rst platypush/plugins/music.snapcast.rst + platypush/plugins/nmap.rst platypush/plugins/pihole.rst platypush/plugins/ping.rst platypush/plugins/printer.cups.rst diff --git a/platypush/plugins/nmap.py b/platypush/plugins/nmap.py new file mode 100644 index 000000000..9f6b93426 --- /dev/null +++ b/platypush/plugins/nmap.py @@ -0,0 +1,30 @@ +from typing import Dict, Any + +from platypush.plugins import Plugin, action + + +class NmapPlugin(Plugin): + """ + Nmap network scanner/mapper integration. + """ + + def __init__(self, **kwargs): + super().__init__(**kwargs) + + @action + def scan(self, hosts: str, ports: str, args: str, sudo: bool = False) -> Dict[str, Any]: + """ + Perform a port scan towards a certain host or network. + + :param hosts: Host name/IP or IP subnet to scan (e.g. ``192.168.1.0/24``). + :param ports: Port number, (comma-separated) list or (dash-separated) range to scan (default: all). + :param args: Additional command line arguments for nmap. + :param sudo: Execute nmap as root through sudo (default: ``False``). + :return: Scan results, as an ip -> host map. + """ + import nmap + nm = nmap.PortScanner() + return nm.scan(hosts=hosts, ports=ports, arguments=args, sudo=sudo).get('scan') + + +# vim:sw=4:ts=4:et: diff --git a/requirements.txt b/requirements.txt index c410c6520..920605091 100644 --- a/requirements.txt +++ b/requirements.txt @@ -221,3 +221,6 @@ croniter # py-cpuinfo # psutil +# Support for nmap integration +# python-nmap + diff --git a/setup.py b/setup.py index b869f71a0..4f6320bb7 100755 --- a/setup.py +++ b/setup.py @@ -275,5 +275,7 @@ setup( 'graphite': ['graphyte'], # Support for CPU and memory monitoring and info 'sys': ['py-cpuinfo', 'psutil'], + # Support for nmap integration + 'nmap': ['python-nmap'], }, )