detect-port
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -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
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
83
1
9255
2
9
+ Addedipv4@0.0.4
+ Addedipv4@0.0.4(transitive)