Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

can-bind-to-host

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

can-bind-to-host - npm Package Compare versions

Comparing version 1.0.2 to 1.1.0

2

dist/bin/can-bind-to-host.js

@@ -9,3 +9,3 @@ #! /usr/bin/env node

var args = process.argv.slice(2);
var _a = args[0], host = _a === void 0 ? "0.0.0.0" : _a, _b = args[1], port = _b === void 0 ? "0" : _b;
var _a = args[0], host = _a === void 0 ? '0.0.0.0' : _a, _b = args[1], port = _b === void 0 ? '0' : _b;
(0, __1.default)(host, +port).then(function (bindable) {

@@ -12,0 +12,0 @@ if (bindable) {

@@ -1,3 +0,3 @@

declare const canBindToHost: (host: string, port?: number) => Promise<boolean>;
declare const canBindToHost: (host?: string, port?: number) => Promise<boolean>;
export default canBindToHost;
export { canBindToHost };

@@ -9,6 +9,7 @@ "use strict";

var canBindToHost = function (host, port) {
if (host === void 0) { host = '0.0.0.0'; }
if (port === void 0) { port = 0; }
var server = null;
return new Promise(function (res) {
if (port >= 0 && port <= 65535)
if (port >= 0 && port <= 65535) {
server = net_1.default

@@ -25,2 +26,3 @@ .createServer()

});
}
else

@@ -27,0 +29,0 @@ res(false);

{
"name": "can-bind-to-host",
"version": "1.0.2",
"version": "1.1.0",
"description": "Utility package to see if the node process can bind to the host or listen on a port. Can be used for checking if a host resolves to localhost.",

@@ -16,4 +16,4 @@ "main": "dist/index.js",

"build": "tsc",
"format": "prettier --write \"src/**\"",
"lint": "tslint -p tsconfig.json"
"lint": "eslint . --ext .ts",
"lint:fix": "eslint --fix . --ext .ts"
},

@@ -33,4 +33,9 @@ "repository": {

"@types/node": "^18.0.4",
"@typescript-eslint/eslint-plugin": "^5.30.6",
"@typescript-eslint/parser": "^5.30.6",
"eslint": "^8.19.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^26.5.3",
"jest": "^28.1.3",
"prettier": "^2.7.1",
"ts-jest": "^28.0.5",

@@ -37,0 +42,0 @@ "ts-node": "^10.8.2",

@@ -17,2 +17,11 @@ # can-bind-to-host

```js
import canBindToHost from 'can-bind-to-host';
// Check if bindable to localhost:8080
canBindToHost("localhost", 8080)
.then(bindable => bindable ? "Yes" : "No")
.then(answer => console.log(answer))
```
[Example](/src/bin/can-bind-to-host.ts)

@@ -55,2 +64,4 @@

For similar reasons as above, this package can return false negatives in case of using this package under an extremely restricted user. As long as the process uses this package can bind to a local port, it will be accurate.
For similar reasons as above, this package can return false negatives in case of using this package under an extremely restricted user. This can be mitigated by running an additional check on `0.0.0.0` to see whether the process has the permissions to bind to localhost at all.
As long as the process uses this package can bind to a local port, it will be accurate.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc