Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
tcp-exists
Advanced tools
Readme
Check if some tcp endpoint (or many) exists. Can be used as a port scanner
65536
endpoints in ~9sec
(via tcpExistsMany)npm i -g tcp-exists
tcp-exists --help # print full cli docs
tcp-exists example.com # scan 20 most popular ports for given host
tcp-exists example.com:22,80,443,8000-10000,27017 # example how to provide list/ranges of ports
tcp-exists example.com:22 another.org:1-65535 # example how to scan several endpoints
npm i tcp-exists --save
Arguments:
host
<string>
port
<string> | <number>
timeout
<number>
- optional number of ms
. Default: DEFAULT_TIMEOUT
signal
<AbortSignal>
- optional. An AbortSignal that may be used to close a socket and return result ASAP.Returns:
<Promise<boolean>>
import { tcpExistsOne } from 'tcp-exists'
const exist = await tcpExistsOne('8.8.8.8', 53, 25)
// check existance of endpoint 8.8.8.8:53 with timeout in 25ms
console.log(exist) // true
It is an async function to check multiple endpoints. If size of endpoints you want to check more than 4096
then recommended to use generator function tcpExistsMany
or increase timeout
.
endpoints
<[string, string|number][]>
- array of [host, port]
options
<object>
- optional
timeout
<number>
- optional number of ms
to execute on chunk. How to pick the best timeout Default: DEFAULT_TIMEOUT
returnOnlyExisted
<boolean>
- optional flag to exclude all non-existed results. Default: true
signal
<AbortSignal>
- optional. An AbortSignal that may be used to close a sockets and return result ASAP.<Promise<[string, string|number, boolean][]>>
- will return array
of [host, port, existed]
import { tcpExistsChunk } from 'tcp-exists'
const endpoints = [
['8.8.8.8', 53],
['8.8.8.8', 80],
['8.8.8.8', 443],
['8.8.8.8', 8080]
]
const result = await tcpExistsChunk(endpoints)
console.log(result)
// all existed endpoints in format [host, port, existed][]
It is an async generator. So you can use it with for await (... of ...)
or as a stream (check nodejs documentation).
Useful to use with large amount of endpoints.
endpoints
<[string, string|number][]|string>
- array of [host, port]
or string in format host:port,port2; host2; host3:port0-port9
options
<object>
- optional
chunkSize
<number>
- optional chunk size of endpoints to process at once. Default: DEFAULT_CHUNK_SIZE
timeout
<number>
- optional number of ms
to execute on chunk. How to pick the best timeout Default: DEFAULT_TIMEOUT
returnOnlyExisted
<boolean>
- optional flag to exclude all non-existed results. Default: true
signal
<AbortSignal>
- optional. An AbortSignal that may be used to close a sockets, stop iteration and return last chunk result ASAP.<AsyncIterable<[host:string, port:string|number, exist:boolean][]>>
- generator will yield array
of [host, port, existed]
import { tcpExistsMany } from 'tcp-exists'
const result = []
for await (const existedEndpoints of tcpExistsMany('localhost:1-65535')) {
result.push(...existedEndpoints)
}
console.log(result)
// all existed endpoints in format [host, port, existed][]
It is a generator. So you can use it with for (... of ...)
or destruct into array [...getEndpoints('example.com:1-65535')]
argument
<string|string[]>
- string in format host:port,port2; host2; host3:port0-port9
or array like this ['host1', 'host2:port1,port2', 'host3:port0-port9']
defaultPorts
<string>
- optional. Comma separated string of ports. Default: DEFAULT_PORTS
<Generator<[string, string|number]>>
- generator will yield array
of [host, port]
import { getEndpoints, tcpExistsOne } from 'tcp-exists'
for (const [host, port] of getEndpoints('localhost:1-65535')) {
if (await tcpExistsOne(host, port)) console.log(host, port, 'exists')
}
<number>
: 2300
<number>
: 250
ms<string>
: '21,22,23,25,53,80,110,111,135,139,143,443,445,993,995,1723,3306,3389,5900,8080'
The best timeout usually is the ninth of the endpoint's size, but at least 100ms
.
For example, better to pick timeout as 220ms
for a chunk of 2000
endpoints.
Also, you can take into account latency to the endpoint.
If your endpoint has latency 300ms
then better to pick timeout as 350ms
and chunkSize as 3100
.
There is better alternative of port scanner to use in shell written in rust RustScan (scans 65536 ports in 3s)
License (MIT)
FAQs
Small and fast functions to check if some tcp endpoint exists
The npm package tcp-exists receives a total of 0 weekly downloads. As such, tcp-exists popularity was classified as not popular.
We found that tcp-exists demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.