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

detect-port

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

detect-port - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

44

lib/index.js

@@ -16,4 +16,4 @@ /* ================================================================

var http = require('http');
var localhost = '0.0.0.0';
var ipv4 = require('ipv4');
var net = require('net');

@@ -31,17 +31,29 @@ var inject = function(port) {

var _detect = function(_fn) {
var server = http.createServer();
var socket = new net.Socket();
socket.once('error', function() {
socket.removeAllListeners('connect');
socket.removeAllListeners('error');
socket.end();
socket.destroy();
socket.unref();
var server = new net.Server();
server.on('error', function() {
inject(port);
port++;
server.listen(port, localhost, function() {
server.once('close', function() {
if (fn) {
_fn(port);
_detect(_fn);
} else {
_fn(null, port);
detect(port)(_fn);
}
});
server.close();
server.listen(port, function() {
server.once('close', function() {
_fn(null, port);
});
server.close();
});
});
server.on('error', function() {
socket.once('connect', function() {
inject(port);

@@ -55,4 +67,14 @@ port++;

}
socket.removeAllListeners('connect');
socket.removeAllListeners('error');
socket.end();
socket.destroy();
socket.unref();
});
socket.connect({
port: port,
host: ipv4
});
};
return fn ? _detect(fn) : _detect;

@@ -59,0 +81,0 @@ }

{
"name": "detect-port",
"version": "0.1.2",
"version": "0.1.3",
"description": "port detector",
"keywords": ["detect", "port", "detect-port"],
"keywords": [
"detect",
"port",
"detect-port"
],
"bin": {

@@ -16,3 +20,4 @@ "detect": "./bin/detect-port",

"dependencies": {
"commander": "~2.8.1"
"commander": "~2.8.1",
"ipv4": "0.0.4"
},

@@ -19,0 +24,0 @@ "devDependencies": {

@@ -57,3 +57,3 @@ detect-port

detect(port, function(_port) {
detect(port, function(error, _port) {

@@ -60,0 +60,0 @@ if (port === _port) {

Sorry, the diff of this file is not supported yet

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