Gathering detailed insights and metrics for netport
Gathering detailed insights and metrics for netport
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
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
1 Stars
6 Commits
1 Watchers
1 Branches
1 Contributors
Updated on Feb 21, 2025
Latest Version
1.3.0
Package Id
netport@1.3.0
Unpacked Size
30.43 kB
Size
7.52 kB
File Count
11
NPM Version
10.9.1
Node Version
22.9.0
Published on
Feb 21, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
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:
npm command
1$ npm i netport
yarn command
1$ yarn add 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(`TCP Port ${result.port}: ${result.success ? 'Open' : 'Closed'} - ${result.message}`); 12 // result object contains - 13 // - port: The port number that was scanned 14 // - success: Indicates if the port is open 15 // - message: A message providing additional information about the scan 16 } catch (err) { 17 // Handling the error. 18 console.error(err); 19 } 20})();
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(`UDP Port ${result.port}: ${result.success ? 'Open' : 'Closed'} - ${result.message}`); 12 // result object contains - 13 // - port: The port number that was scanned 14 // - success: Indicates if the port is open 15 // - message: A message providing additional information about the scan 16 } catch (err) { 17 // Handling the error. 18 console.error(err); 19 } 20})();
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(`TCP 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(`UDP 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.