A simple TCP ping utility to ping a port of an IP or domain
npm install tcp-ping-port



pingping uses ICMP protocol which is not permitted by AWS/Azure functions | Protocol | Send (B)) | Receive (B) | Total (B) | Data saving |
| -------- | --------- | ------------ | ---------- | ----------- |
| TCP | 228 | 126 | 354 | 0% |
| ICMP | 98 | 98 | 196 | 45% |
#### TCP Ping | No. | Time | Source | Destination | Protocol | Length | Info | #### ICMP ping > NOTE: The first 2 DNS resolution calls are same in both cases for IPv4 and are not included in the total data usagage.
The numbers are based on data reported by Wireshark
| --- | ---- | ------ | ----------- | -------- | ------ | ---- |
| 1 | 0.000000 | x.x.x.x | y.y.y.y | DNS | 70 | Standard query 0xfe55 A google.com |
| 2 | 0.000393 | y.y.y.y | x.x.x.x | DNS | 86 | Standard query response 0xfe55 A google.com A 172.217.165.14 |
| | | | | | | |
| 3 | 0.001364 | x.x.x.x | 172.217.165.14 | TCP | 66 | 49985 → 80 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 WS=256 SACK_PERM=1 |
| 4 | 0.012339 | 172.217.165.14 | x.x.x.x | TCP | 66 | 80 → 49985 [SYN, ACK] Seq=0 Ack=1 Win=65535 Len=0 MSS=1430 SACK_PERM=1 WS=256 |
| 5 | 0.012412 | x.x.x.x | 172.217.165.14 | TCP | 54 | 49985 → 80 [ACK] Seq=1 Ack=1 Win=262912 Len=0 |
| 6 | 0.013110 | x.x.x.x | 172.217.165.14 | TCP | 54 | 49985 → 80 [FIN, ACK] Seq=1 Ack=1 Win=262912 Len=0 |
| 7 | 0.024927 | 172.217.165.14 | x.x.x.x | TCP | 60 | 80 → 49985 [FIN, ACK] Seq=1 Ack=2 Win=65536 Len=0 |
| 8 | 0.024987 | x.x.x.x | 172.217.165.14 | TCP | 54 | 49985 → 80 [ACK] Seq=2 Ack=2 Win=262912 Len=0 |
| No. | Time | Source | Destination | Protocol | Length | Info |
| --- | ---- | ------ | ----------- | -------- | ------ | ---- |
| 1 | 0.000000 | x.x.x.x | y.y.y.y | DNS | 70 | Standard query 0xff9e A google.com|
| 2 | 0.003286 | y.y.y.y | x.x.x.x | DNS | 86 | Standard query response 0xff9e A google.com A 172.217.165.14|
| 3 | 0.040291 | x.x.x.x | 172.217.165.14| ICMP | 98 | Echo (ping) request id=0x0279, seq=1/256, ttl=128 (reply in 6)|
| 4 | 0.064258 | 172.217.165.14 | x.x.x.x | ICMP | 98 | Echo (ping) reply id=0x0279, seq=1/256, ttl=112 (request in 5)|
$ npm install tcp-ping-port --save
`
back to top
How to use
---Simple examples
`js
const { tcpPingPort } = require("tcp-ping-port")tcpPingPort("google.com").then(({online}) => {
// ....
})
`With additional options
`js
const { tcpPingPort } = require("tcp-ping-port")
const dns = require('dns')
const options = {
socketTimeout: 11000,
dnsTimeout: 10000,
dnsServers: '8.8.8.8', // google DNS
}
tcpPingPort("google.com", 80, options).then(({online, ping}) => {
// ....
})
`Check if host is offline
`js
const { tcpPingPort } = require("tcp-ping-port")tcpPingPort("google.com").then(result => {
if (!result.online && result.error.code === 'TCPPINGTIMEOUT') {
// your code when host is not accessible....
}
})
`Dependencies
* dns-fast-resolver - to resolve multiple domains at the same time and to handle any errors while resolving the domain name. Also, to skip the whole dns resolution if host name is an IP address.
* lodash
* maketypeAPI
$3
Attemps to open and close TCP connection* hostname
Host name or an IP address to try to connect to
* port Port number
* options