Gathering detailed insights and metrics for netport
Gathering detailed insights and metrics for netport
Fast, CPU-friendly, minimalist, light-weight promise-based TCP/UDP port(s) scanner
npm install netport
Typescript
Module System
Node Version
NPM Version
72.5
Supply Chain
99.4
Quality
85.7
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
232
Last Day
3
Last Week
10
Last Month
232
Last Year
232
1 Stars
5 Commits
1 Watching
1 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
1.2.5
Package Id
netport@1.2.5
Unpacked Size
29.40 kB
Size
7.42 kB
File Count
11
NPM Version
10.9.1
Node Version
22.9.0
Publised On
17 Jan 2025
Cumulative downloads
Total Downloads
Last day
-25%
3
Compared to previous day
Last week
-86.5%
10
Compared to previous week
Last month
0%
232
Compared to previous month
Last year
0%
232
Compared to previous year
4
Fast, CPU-friendly, minimalist, light-weight promise-based TCP/UDP port(s) scanner.
To get started with netport
, simply run the following command in your terminal:
1$ npm i netport
First, require this library to your project as follows:
1const netport = require("netport");
If it's an ES Module then import it to your project as follows:
1import netport from "netport";
New to Promises?
If you're not familiar with promises, check out the MDN documentation to learn more.
Once you've imported netport
into your project, you're ready to start working using netport
!
The scanPort()
function scans a specified port on a specified host and checks whether it is open for the specified protocol (TCP or UDP).
The scanPort() function parameters are as follows -
type
: The type of port to scan ("TCP"
or "UDP"
). Default is "TCP"
.port
: The port number to check.host
: The hostname or IP address of the target.timeout
: The timeout duration in milliseconds. Default is 1000 ms
.Example demonstrating TCP port scan:
1// First example regarding TCP port scan. 2(async () => { 3 try { 4 const result = await netport.scanPort({ 5 type: "TCP", // Specify the type of port to scan (TCP) 6 port: 53, // DNS port (commonly used for DNS queries) 7 host: "8.8.8.8", // Google Public DNS IP address 8 timeout: 1000 // Set timeout to 1000 milliseconds 9 }); 10 11 console.log(result); 12 // result object contains - 13 // - success: Indicates if the port is open 14 // - message: A message providing additional information about the scan 15 } catch (err) { 16 // Handling the error. 17 console.error(err); 18 } 19})();
Example demonstrating UDP port scan:
1// Second example regarding UDP port scan. 2(async () => { 3 try { 4 const result = await netport.scanPort({ 5 type: "UDP", // Specify the type of port to scan (UDP) 6 port: 123, // NTP port (commonly used for Network Time Protocol) 7 host: "pool.ntp.org", // Public NTP server 8 timeout: 1000 // Set timeout to 1000 milliseconds 9 }); 10 11 console.log(result); 12 // result object contains - 13 // - success: Indicates if the port is open 14 // - message: A message providing additional information about the scan 15 } catch (err) { 16 // Handling the error. 17 console.error(err); 18 } 19})();
scanPorts()
FunctionThe scanPorts()
function scans a range of ports on a specified host and checks whether they are open for the specified protocol (TCP or UDP).
The scanPorts() function parameters are as follows -
type
: The type of port to scan ("TCP"
or "UDP"
). Default is "TCP"
.from
: The starting port number.to
: The ending port number.host
: The hostname or IP address of the target.timeout
: The timeout duration in milliseconds. Default is 1000 ms
.maxConcurrency
: The maximum number of concurrent port checks to perform. Default is 100
.Example demonstrating TCP ports scan:
1// First example regarding TCP ports scan.
2(async () => {
3 try {
4 const results = await netport.scanPorts({
5 type: "TCP", // Specify the type of ports to scan (TCP)
6 from: 1, // Starting from port 1
7 to: 100, // Scanning up to port 100
8 host: "8.8.8.8", // Google Public DNS IP address
9 timeout: 1000, // Set timeout to 1000 milliseconds for each port check
10 maxConcurrency: 50 // Optional: Set maximum concurrent connections (default is 100)
11 });
12
13 // Results returned is an array of objects.
14 results.forEach(result => {
15 console.log(`Port ${result.port}: ${result.success ? 'Open' : 'Closed'} - ${result.message}`);
16 // - result.port: The port number that was scanned
17 // - result.success: Indicates if the port is open (true) or closed (false)
18 // - result.message: Additional information about the scan result
19 });
20 } catch (err) {
21 // Handling any errors that occur during the scan.
22 console.error('Error during port scan:', err);
23 }
24})();
25
Example demonstrating UDP ports scan:
1// Second example regarding UDP ports scan.
2(async () => {
3 try {
4 const results = await netport.scanPorts({
5 type: "UDP", // Specify the type of ports to scan (UDP)
6 from: 1, // Starting from port 1
7 to: 100, // Scanning up to port 100
8 host: "pool.ntp.org", // Public NTP server for time synchronization
9 timeout: 1000, // Set timeout to 1000 milliseconds for each port check
10 maxConcurrency: 50 // Optional: Set maximum concurrent connections (default is 100)
11 });
12
13 // Results returned is an array of objects.
14 results.forEach(result => {
15 console.log(`Port ${result.port}: ${result.success ? 'Open' : 'Closed'} - ${result.message}`);
16 // - result.port: The port number that was scanned
17 // - result.success: Indicates if the port is open (true) or closed (false)
18 // - result.message: Additional information about the scan result
19 });
20 } catch (err) {
21 // Handling any errors that occur during the scan.
22 console.error('Error during UDP port scan:', err);
23 }
24})();
25
netport
is released under the MIT License.
View the full license terms here.
Found a bug or want a new feature?
Report issues and request features on the netport issue tracker.
Thanks for reading!
Have a great day ahead :D
No vulnerabilities found.
No security vulnerabilities found.