NetworkScanner


NameNetworkScanner JSON
Version 2.0.0 PyPI version JSON
download
home_pagehttps://github.com/mauricelambert/NetworkScanner
SummaryThis module implements a NetworkScanner.
upload_time2023-05-02 10:41:04
maintainerMaurice Lambert
docs_urlNone
authorMaurice Lambert
requires_python>=3.8
licenseGPL-3.0 License
keywords network scanner discovery host ping nmap security scapy arp
VCS
bugtrack_url
requirements PythonToolsKit scapy
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ![NetworkScanner logo](https://mauricelambert.github.io/info/python/security/NetworkScanner_small.png "NetworkScanner logo")

# NetworkScanner

## Description

This package implements an asynchronous network scanner (using scapy or asyncio).

## Requirements

This package require: 
 - python3
 - python3 Standard Library
 - PythonToolsKit

Optional:
 - Scapy

## Installation

```bash
pip install NetworkScanner 
```

## Usages

### Command lines

```bash
# Python executable
python3 NetworkScanner.pyz -h
# or
chmod u+x NetworkScanner.pyz
./NetworkScanner.pyz --help

# Python module
python3 -m NetworkScanner -t 172.18.0.1-172.18.0.15

# Entry point (console)
NetworkScanner -d --noping --hostname --ports 22 80 -p 445 139 443 -T 1 -R -s -t 172.18.0.0/28
NetworkScanner -i 172.18.0. -P -t 172.18.0.0/28 # Passive scan using scapy sniffer
```

### Python3

```python
# Simple usage to print results in your console
from NetworkScanner import NetworkScanner, logger
scanner = NetworkScanner({"172.18.0.1", "172.18.0.3"})
scanner.scan()      # Without scapy

# Custom behaviors

def do_IP_UP(ip, reason, detail = None):
    print(f"{ip} is UP ({reason} {detail})")

scanner.handle_UP = do_IP_UP
scanner.scan(True)  # With scapy

scanner.hosts_up    # List of IP addresses used
scanner.hosts_down  # List of unused IP addresses

from scapy.all import *
scanner = NetworkScanner({"172.18.0.1"}, False, [22, 80], False, True, False, 1, conf.iface)
scanner.handle_UP = do_IP_UP
scanner.handle_DOWN = print
scanner.scan()

logger.setLevel(10) # debug mode

class CustomNetworkScanner(NetworkScanner):
    def handle_UP(self, ip: str, detection_type: str, details = None): # details is a kwarg
        print(f"IP: {ip} is UP (detection type: {detection_type}, details: {details}")
    def handle_DOWN(self, ip: str):
        print(f"IP: {ip} is DOWN")

scanner = NetworkScanner({"172.18.0.1", "172.18.0.3"})
scanner.scan()
scanner.scan(passive=True) # passive mode using scapy sniffer
```

## Useful usages

With scapy, *hosts discovery (best performances)*:

```bash
NetworkScanner --noping -T 1 -t [targets]
```

```python
from NetworkScanner import NetworkScanner
from scapy.all import conf

scanner = NetworkScanner(
    {},
    ping=False,
    ports=[],
    arp=True,
    hostname=False,
    real_time=False,
    timeout=1,
    iface=conf.iface,
)
scanner.scan(True)
```

Without scapy, *hosts discovery*:

```bash
NetworkScanner -t [targets]
```

```python
from NetworkScanner import NetworkScanner
scanner = NetworkScanner(
    {},
    ping=True,
    ports=[],
    arp=True,
    hostname=False,
    real_time=False,
    timeout=1,
)
scanner.scan()
```

Without scapy, *opened port && hosts discovery*:

```python
from NetworkScanner import NetworkScanner

def host_up(ip: str, method: str, port: int = None):
    if method == 'tcp':
        print(f"{ip}:{port} is open.")
    else:
        print(f"{ip} is UP.")

scanner = NetworkScanner(
    {},
    ping=False,
    ports=[22, 80, 443],
    arp=True,
    hostname=False,
    real_time=False,
    timeout=1,
)
scanner.handle_UP = host_up
scanner.scan(False)
```

## Links

 - [Github Page](https://github.com/mauricelambert/NetworkScanner)
 - [Pypi](https://pypi.org/project/NetworkScanner/)
 - [Documentation](https://mauricelambert.github.io/info/python/security/NetworkScanner.html)
 - [Executable](https://mauricelambert.github.io/info/python/security/NetworkScanner.pyz)

## Help

```text
usage: NetworkScanner.py [-h] [--interface INTERFACE] --targets TARGETS [TARGETS ...] [--noping] [--noarp]
                         [--hostname] [--ports PORTS [PORTS ...]] [--timeout TIMEOUT] [--no-realtime] [--debug]
                         [--print-ip] [--force-asynchronous] [--passive-scan]

This program scans networks and IP address ranges.

options:
  -h, --help            show this help message and exit
  --interface INTERFACE, -i INTERFACE
                        Part of the IP, MAC or name of the interface
  --targets TARGETS [TARGETS ...], -t TARGETS [TARGETS ...]
                        Targets from networks and IP address ranges.
  --noping, -g          No ping detection. [Without scapy ping is required for ARP detection]
  --noarp, -A           No arp cache.
  --hostname, -H        Test the hostname resolution to defined if host is UP (longer).
  --ports PORTS [PORTS ...], -p PORTS [PORTS ...]
                        Test the TCP port connections to defined if the host is UP.
  --timeout TIMEOUT, -T TIMEOUT
                        Connections timeout.
  --no-realtime, -R     Do not print results in real time.
  --debug, -d           Debug mode (logger level debug).
  --print-ip, -I        Print only the IP address if UP.
  --force-asynchronous, --async, -a
                        Force asynchronous mode, using asyncio instead of scapy.
  --passive-scan, --passive, -P
                        Passive scan, sniff the network packets to identify who is up. This scan is endless because
                        you can never be sure to have detected all the IP addresses.
```

## Licence

Licensed under the [GPL, version 3](https://www.gnu.org/licenses/).

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/mauricelambert/NetworkScanner",
    "name": "NetworkScanner",
    "maintainer": "Maurice Lambert",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "mauricelambert434@gmail.com",
    "keywords": "Network,Scanner,Discovery,Host,Ping,nmap,Security,Scapy,ARP",
    "author": "Maurice Lambert",
    "author_email": "mauricelambert434@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/05/fa/bcfa11bb40c372bbd536e83118d5a446c673e466bbc8f5baf6d8cc9cde39/NetworkScanner-2.0.0.tar.gz",
    "platform": "Windows",
    "description": "![NetworkScanner logo](https://mauricelambert.github.io/info/python/security/NetworkScanner_small.png \"NetworkScanner logo\")\n\n# NetworkScanner\n\n## Description\n\nThis package implements an asynchronous network scanner (using scapy or asyncio).\n\n## Requirements\n\nThis package require: \n - python3\n - python3 Standard Library\n - PythonToolsKit\n\nOptional:\n - Scapy\n\n## Installation\n\n```bash\npip install NetworkScanner \n```\n\n## Usages\n\n### Command lines\n\n```bash\n# Python executable\npython3 NetworkScanner.pyz -h\n# or\nchmod u+x NetworkScanner.pyz\n./NetworkScanner.pyz --help\n\n# Python module\npython3 -m NetworkScanner -t 172.18.0.1-172.18.0.15\n\n# Entry point (console)\nNetworkScanner -d --noping --hostname --ports 22 80 -p 445 139 443 -T 1 -R -s -t 172.18.0.0/28\nNetworkScanner -i 172.18.0. -P -t 172.18.0.0/28 # Passive scan using scapy sniffer\n```\n\n### Python3\n\n```python\n# Simple usage to print results in your console\nfrom NetworkScanner import NetworkScanner, logger\nscanner = NetworkScanner({\"172.18.0.1\", \"172.18.0.3\"})\nscanner.scan()      # Without scapy\n\n# Custom behaviors\n\ndef do_IP_UP(ip, reason, detail = None):\n    print(f\"{ip} is UP ({reason} {detail})\")\n\nscanner.handle_UP = do_IP_UP\nscanner.scan(True)  # With scapy\n\nscanner.hosts_up    # List of IP addresses used\nscanner.hosts_down  # List of unused IP addresses\n\nfrom scapy.all import *\nscanner = NetworkScanner({\"172.18.0.1\"}, False, [22, 80], False, True, False, 1, conf.iface)\nscanner.handle_UP = do_IP_UP\nscanner.handle_DOWN = print\nscanner.scan()\n\nlogger.setLevel(10) # debug mode\n\nclass CustomNetworkScanner(NetworkScanner):\n    def handle_UP(self, ip: str, detection_type: str, details = None): # details is a kwarg\n        print(f\"IP: {ip} is UP (detection type: {detection_type}, details: {details}\")\n    def handle_DOWN(self, ip: str):\n        print(f\"IP: {ip} is DOWN\")\n\nscanner = NetworkScanner({\"172.18.0.1\", \"172.18.0.3\"})\nscanner.scan()\nscanner.scan(passive=True) # passive mode using scapy sniffer\n```\n\n## Useful usages\n\nWith scapy, *hosts discovery (best performances)*:\n\n```bash\nNetworkScanner --noping -T 1 -t [targets]\n```\n\n```python\nfrom NetworkScanner import NetworkScanner\nfrom scapy.all import conf\n\nscanner = NetworkScanner(\n    {},\n    ping=False,\n    ports=[],\n    arp=True,\n    hostname=False,\n    real_time=False,\n    timeout=1,\n    iface=conf.iface,\n)\nscanner.scan(True)\n```\n\nWithout scapy, *hosts discovery*:\n\n```bash\nNetworkScanner -t [targets]\n```\n\n```python\nfrom NetworkScanner import NetworkScanner\nscanner = NetworkScanner(\n    {},\n    ping=True,\n    ports=[],\n    arp=True,\n    hostname=False,\n    real_time=False,\n    timeout=1,\n)\nscanner.scan()\n```\n\nWithout scapy, *opened port && hosts discovery*:\n\n```python\nfrom NetworkScanner import NetworkScanner\n\ndef host_up(ip: str, method: str, port: int = None):\n    if method == 'tcp':\n        print(f\"{ip}:{port} is open.\")\n    else:\n        print(f\"{ip} is UP.\")\n\nscanner = NetworkScanner(\n    {},\n    ping=False,\n    ports=[22, 80, 443],\n    arp=True,\n    hostname=False,\n    real_time=False,\n    timeout=1,\n)\nscanner.handle_UP = host_up\nscanner.scan(False)\n```\n\n## Links\n\n - [Github Page](https://github.com/mauricelambert/NetworkScanner)\n - [Pypi](https://pypi.org/project/NetworkScanner/)\n - [Documentation](https://mauricelambert.github.io/info/python/security/NetworkScanner.html)\n - [Executable](https://mauricelambert.github.io/info/python/security/NetworkScanner.pyz)\n\n## Help\n\n```text\nusage: NetworkScanner.py [-h] [--interface INTERFACE] --targets TARGETS [TARGETS ...] [--noping] [--noarp]\n                         [--hostname] [--ports PORTS [PORTS ...]] [--timeout TIMEOUT] [--no-realtime] [--debug]\n                         [--print-ip] [--force-asynchronous] [--passive-scan]\n\nThis program scans networks and IP address ranges.\n\noptions:\n  -h, --help            show this help message and exit\n  --interface INTERFACE, -i INTERFACE\n                        Part of the IP, MAC or name of the interface\n  --targets TARGETS [TARGETS ...], -t TARGETS [TARGETS ...]\n                        Targets from networks and IP address ranges.\n  --noping, -g          No ping detection. [Without scapy ping is required for ARP detection]\n  --noarp, -A           No arp cache.\n  --hostname, -H        Test the hostname resolution to defined if host is UP (longer).\n  --ports PORTS [PORTS ...], -p PORTS [PORTS ...]\n                        Test the TCP port connections to defined if the host is UP.\n  --timeout TIMEOUT, -T TIMEOUT\n                        Connections timeout.\n  --no-realtime, -R     Do not print results in real time.\n  --debug, -d           Debug mode (logger level debug).\n  --print-ip, -I        Print only the IP address if UP.\n  --force-asynchronous, --async, -a\n                        Force asynchronous mode, using asyncio instead of scapy.\n  --passive-scan, --passive, -P\n                        Passive scan, sniff the network packets to identify who is up. This scan is endless because\n                        you can never be sure to have detected all the IP addresses.\n```\n\n## Licence\n\nLicensed under the [GPL, version 3](https://www.gnu.org/licenses/).\n",
    "bugtrack_url": null,
    "license": "GPL-3.0 License",
    "summary": "This module implements a NetworkScanner.",
    "version": "2.0.0",
    "project_urls": {
        "Documentation": "https://mauricelambert.github.io/info/python/security/NetworkScanner.html",
        "Executable": "https://mauricelambert.github.io/info/python/security/NetworkScanner.pyz",
        "Homepage": "https://github.com/mauricelambert/NetworkScanner"
    },
    "split_keywords": [
        "network",
        "scanner",
        "discovery",
        "host",
        "ping",
        "nmap",
        "security",
        "scapy",
        "arp"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "05fabcfa11bb40c372bbd536e83118d5a446c673e466bbc8f5baf6d8cc9cde39",
                "md5": "612773f97f0e5f268789fe14285753d0",
                "sha256": "b269c93e0ecd92086663c88176e6ff2b78f6609df476030f70d2b36aff4dbe2b"
            },
            "downloads": -1,
            "filename": "NetworkScanner-2.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "612773f97f0e5f268789fe14285753d0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 24370,
            "upload_time": "2023-05-02T10:41:04",
            "upload_time_iso_8601": "2023-05-02T10:41:04.306995Z",
            "url": "https://files.pythonhosted.org/packages/05/fa/bcfa11bb40c372bbd536e83118d5a446c673e466bbc8f5baf6d8cc9cde39/NetworkScanner-2.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-05-02 10:41:04",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "mauricelambert",
    "github_project": "NetworkScanner",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "PythonToolsKit",
            "specs": []
        },
        {
            "name": "scapy",
            "specs": []
        }
    ],
    "lcname": "networkscanner"
}
        
Elapsed time: 0.12382s