{"id":16259383,"url":"https://github.com/justintaddei/tcp-ping","last_synced_at":"2025-03-16T13:30:57.698Z","repository":{"id":34206808,"uuid":"170391918","full_name":"justintaddei/tcp-ping","owner":"justintaddei","description":"A simple TCP ping util, written in Typescript, to test the connectivity of a device.","archived":false,"fork":false,"pushed_at":"2025-03-10T00:11:08.000Z","size":1258,"stargazers_count":8,"open_issues_count":2,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-10T01:31:08.456Z","etag":null,"topics":["network","ping","probe","tcp","tcp-ip","tcp-protocol"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/justintaddei.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"custom":"buymeacoffee.com/justintaddei"}},"created_at":"2019-02-12T21:10:40.000Z","updated_at":"2025-03-10T00:10:01.000Z","dependencies_parsed_at":"2024-01-15T01:40:07.634Z","dependency_job_id":"a7e7e654-e552-4d07-bfb9-9c96a74dfc42","html_url":"https://github.com/justintaddei/tcp-ping","commit_stats":{"total_commits":357,"total_committers":6,"mean_commits":59.5,"dds":0.1204481792717087,"last_synced_commit":"f8e1461aa9adb6037d1dbccc1b80e7ba8463284a"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justintaddei%2Ftcp-ping","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justintaddei%2Ftcp-ping/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justintaddei%2Ftcp-ping/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justintaddei%2Ftcp-ping/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/justintaddei","download_url":"https://codeload.github.com/justintaddei/tcp-ping/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243815571,"owners_count":20352193,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["network","ping","probe","tcp","tcp-ip","tcp-protocol"],"created_at":"2024-10-10T16:01:37.243Z","updated_at":"2025-03-16T13:30:57.384Z","avatar_url":"https://github.com/justintaddei.png","language":"TypeScript","funding_links":["buymeacoffee.com/justintaddei"],"categories":[],"sub_categories":[],"readme":"# tcp-ping\n\n[![checks](https://github.com/justintaddei/tcp-ping/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/justintaddei/tcp-ping/actions/workflows/tests.yml)\n![](https://img.shields.io/github/issues-raw/justintaddei/tcp-ping.svg?style=flat)\n![](https://img.shields.io/npm/v/@network-utils/tcp-ping.svg?style=flat)\n![](https://img.shields.io/npm/dt/@network-utils/tcp-ping.svg?style=flat)\n![](https://img.shields.io/badge/language-typescript-blue.svg?style=flat)\n![](https://img.shields.io/npm/l/@network-utils/tcp-ping.svg?style=flat)\n[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat)](https://github.com/prettier/prettier)\n\nA simple promise-based TCP ping util, written in Typescript, to test the reachability and latency of a host.\n\n## Installation\n\n```bash\n$ npm install @network-utils/tcp-ping --save\n```\n\n## Usage\n\n### `ping(options?: Partial\u003cIPingOptions\u003e, progress?: (progress, total) =\u003e void): Promise\u003cIPingResult\u003e`\n\nPings the given host and returns an object containing the latency of the connection\nand any errors that may have occured.\n\n\u003e **NOTE:** Attempts are not concurrent. As such if a host is unreachable and you provide options { attempts: 60, timeout: 1000 } then `ping` will not resolve for a full minute!\n\n```typescript\nimport { ping } from '@network-utils/tcp-ping'\n\nping({\n  // The IP address or hostname of the host you want\n  // to ping. Defaults to 127.0.0.1 (localhost)\n  address: '192.168.1.47',\n  // How many times do you want want to\n  // attempt to reach the host? Default is 10\n  attempts: 10,\n  // What port do you want to connect on?\n  // Default is 80\n  port: 80,\n  // How long do you want to wait (in milliseconds)\n  // before assuming an attempt has failed?\n  // Default is 3000 (3 seconds)\n  timeout: 3000\n}, update).then(result =\u003e {\n  console.log('ping result:', result)\n\n\n    // ping result:\n    {\n      averageLatency: 19.2753,\n      errors: [\n        {\n          // Which attempt failed\n          attempt: 3,\n          error: Error('Request timeout')\n        }\n      ],\n      maximumLatency: 35.1978,\n      minimumLatency: 3.7716,\n      options: {\n        address: '192.168.1.47',\n        attempts: 10,\n        port: 80,\n        timeout: 3000\n      }\n    }\n})\n\nfunction update(progress, total) {\n  console.log(progress, '/', total)\n  /*\n    1 / 10\n    2 / 10\n    3 / 10\n    ...\n  */\n}\n```\n\n### `probe(port: number, address?: string, timeout?: number): Promise\u003cboolean\u003e`\n\nMakes one attempt to reach the host and returns a `boolean` indicating whether or not it was successful.  \nIf `address` is not provided it will default to `'127.0.0.1'`.  \nIf `timeout` is not provided it will default to `3000`.\n\n```typescript\nimport { probe } from '@network-utils/tcp-ping'\n\nprobe(80, '192.168.1.47', 500).then(hostReachable =\u003e {\n  if (hostReachable) console.log('The host is reachable 🙌')\n  else console.log('The host is not reachable 🤐')\n})\n\n// Or\n\nconst hostReachable = await probe(80, '192.168.1.47', 500)\n```\n\n## Errors\n\n- All methods will throw a `\"Negative port\"` error if `port \u003c 1`.\n\n---\n\n## Testing\n\n```bash\n$ git clone https://github.com/justintaddei/tcp-ping.git\n$ cd tcp-ping\n$ npm install\n$ npm test\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjustintaddei%2Ftcp-ping","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjustintaddei%2Ftcp-ping","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjustintaddei%2Ftcp-ping/lists"}