scannet

1.0.2 • Public • Published

Port Scanner

A simple and efficient port scanner written in Node.js. This utility allows you to scan a range of IP addresses and ports within a specified subnet, checking for open ports.

Features

Subnet Scanning: Scan an entire subnet for open ports. Port Range Parsing: Parse and scan a range of ports (e.g., 3000-3010). Concurrency Control: Control the number of concurrent port scans using a configurable queue. Timeout Handling: Set a timeout for each port scan to avoid hanging on closed or unresponsive ports. Installation To use this port scanner in your project, you need to install the required dependencies:

npm install ip net p-queue
Usage
Importing the Module
First, require the module in your Node.js application:
const { startScan, parseData, scanPort } = require('./path/to/your/module');
Scanning a Subnet
You can scan a subnet by specifying the subnet and a range of ports:
const subnet = '192.168.1.0/24';  // Subnet to scan
const portRange = '3000-3010,80,443';  // Ports to scan

// Start scanning
startScan(subnet, portRange, 50);

Example Output The scan will print output to the console indicating which ports are open or closed:

端口 192.168.1.1:3000 拒绝
端口 192.168.1.1:3001 开放
端口 192.168.1.1:3002 超时

cli

Usage: cli [options]

选项: --version,显示版本号,[布尔]
-s, --subnet,The subnet to scan in CIDR notation (e.g., 192.168.0.0/24), [字符串] [必需]
-p, --ports The ports to scan, can be a single port, comma-separated list, or range (e.g., 80,443 or 1000-2000) [字符串] [必需]
-c, --concurrency The concurrency level for scanning [数字] [默认值: 100]
-h, --help,显示帮助信息 ,[布尔]

示例:

scannet -s 192.168.0.0/24 -p 22,80,443  
#Scan a subnet for open ports

缺少这些必须的选项:subnet, ports

Functions

startScan(subnet, portStr, concurrency) Parameters:

subnet: A string representing the subnet in CIDR notation (e.g., 192.168.1.0/24). portStr: A string representing the range of ports to scan (e.g., '80,443,3000-3010'). concurrency: An optional integer to control the number of concurrent scans (default is 100). Description: Starts scanning the specified subnet for open ports within the given port range.

parseData(dataString) Parameters:

dataString: A string representing a comma-separated list of ports or port ranges (e.g., '80,443,3000-3010'). Returns: An array of integers representing the parsed ports.

Description: Parses the port string into an array of individual port numbers.

scanPort(targetHost, port, timeout) Parameters:

targetHost: A string representing the IP address of the target host. port: An integer representing the port number to scan. timeout: An optional integer to set the scan timeout in milliseconds (default is 1000). Returns: A promise that resolves with an object containing the port and targetHost if the port is open, or null if it is closed or timed out.

Description: Scans a specific port on a target host and checks if it is open, closed, or timed out.

Contributing Feel free to submit issues or pull requests. Contributions are welcome!

License

This project is licensed under the MIT License.

Readme

Keywords

Package Sidebar

Install

npm i scannet

Weekly Downloads

4

Version

1.0.2

License

ISC

Unpacked Size

9.02 kB

Total Files

5

Last publish

Collaborators

  • cx2017