npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

netmap

v1.0.6

Published

A set of wrapper classes for programmatically accessing the command line tool nmap.

Downloads

15

Readme

NetMap

A wrapper for programmatically accessing the command line tool Nmap. You must have Nmap installed on your device, but as long as it is, anything described below will work.

How to Use

The import exposes the classes Subnet and Host. Every method that yields data returns a Promise.

Subnet

This is for scanning all IPs in a subnet.

Interface

  • constructor(addr[, options = {bits = 24, outputFile = null}])

  • setIP(addr): Sets the start IP address of the range. This method is recommended for setting this property, as it will verify that the new address is in a valid IPv4 format.

  • setBits(bits): Sets the number of bits for the IP range. This method is recommended for setting this property, as it will verify that the new value is valid.

  • getHosts([options = {outputFile = null}]): Finds all hosts in the subnet without checking any ports.

  • scanForPorts(ports[, options = {outputFile = null, version = false, udp = false}]): Scans all "up" hosts in the subnet and returns the hosts' status for the input ports. The ports argument can be a single port or an array. The outputFile option may be used to specify an override output file to use instead of the output file specified in the constructor. If no output file is specified in either the constructor OR this method, the data will not be written to any file. The version option will attempt to perform version detection, and the udp option will attempt to form UDP connections.

  • scanForOpenPorts(ports[, options = {outputFile = null, all = false, version = false, udp = false}]): Scans all "up" hosts in the subnet and returns only the hosts with the input ports open. The ports argument can be a single port or an array. If the all option is set to true, only the hosts with all the input ports open will be returned.

Data Format

The general format for the responses from the scanForPorts and scanForOpenPorts methods is

[
  {
    "ip": "x.x.x.x",
    "name": "some-device",
    "status": "up",
    "ports": [
      {
        "port": 515,
        "open": true,
        "protocol": "tcp",
        "serviceName": "printer",
        "portDetails": ""
      }
      ...
    ]
  },
  ...
]

For getHosts, the format is

[
  {
    "ip": "x.x.x.x",
    "name": "some-device"
  },
  ...
]

Example

const { Subnet } = require('netmap');

const subnet = new Subnet('192.168.86.0', { outputFile: './data.json' });

subnet.scanForOpenPorts([515, 9100]) // `nmap -sV 192.168.86.0/24 -p 515,9100 -oG - | grep -e open`
	.then(d => ...)
	.catch(console.error);

Host

This is for scanning a single host.

Interface

  • constructor(addr[options = {outputFile = null}])

  • scan([options = {outputFile = null, version = false, udp = false, flags = []}]): Returns open ports on the host in the same format as the ports property of a single host from the subnet scans. The flags option is an array of flags to be appended onto the Nmap call, each separated by a space.

  • scanCommon([options = {outputFile = null, flags = []}]): Checks the 100 most common ports and returns open ports on the host in the same format as the ports property of a single host from the subnet scans.

  • scanPorts(ports[, options = {outputFile = null, version = false, udp = false, flags = []}]): Returns port data for each input port. The ports argument can be a single port or an array.

Example

const { Host } = require('netmap');

const host = new Host('192.168.86.54');

host.scanPorts([515, 9100]) // `nmap -sT 192.168.86.54 -p 515,9100`
  .then(d => ...)
  .catch(console.error);