An open source, self-hosted, real-time port monitoring and discovery tool.
fix: deduplicate IPv4/IPv6 and internal port entries (#84)
Mostafa Wahied014df8b68b40
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex e99573e..16cacc6 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -2,6 +2,12 @@All notable changes to portracker will be documented in this file.+## [1.3.2] - 2026-02-03++### Fixed++- **Duplicate Ports**: Fixed duplicate port entries caused by IPv4/IPv6 wildcard addresses and internal port detection (resolves #82)+## [1.3.1] - 2026-02-03### Fixeddiff --git a/backend/collectors/base_collector.js b/backend/collectors/base_collector.jsindex 9720711..157697f 100644--- a/backend/collectors/base_collector.js+++ b/backend/collectors/base_collector.js@@ -139,11 +139,15 @@ class BaseCollector {* @returns {Object} Normalized port entry*/normalizePortEntry(entry) {+ let hostIp = entry.host_ip || "0.0.0.0";+ if (hostIp === "::" || hostIp === "[::]" || hostIp === "*") {+ hostIp = "0.0.0.0";+ }return {source: entry.source || this.platform,owner: entry.owner || "unknown",protocol: entry.protocol || "tcp",- host_ip: entry.host_ip || "0.0.0.0",+ host_ip: hostIp,host_port: parseInt(entry.host_port, 10) || 0,target: entry.target || null,container_id: entry.container_id || null,diff --git a/backend/collectors/docker_collector.js b/backend/collectors/docker_collector.jsindex f9ccbd4..2b7f412 100644--- a/backend/collectors/docker_collector.js+++ b/backend/collectors/docker_collector.js@@ -29,6 +29,13 @@ class DockerCollector extends BaseCollector {this.dockerApi = new DockerAPIClient();}+ _normalizeHostIp(ip) {+ if (!ip || ip === '' || ip === '::' || ip === '::0' || ip === '0.0.0.0') {+ return '0.0.0.0';+ }+ return ip;+ }+async initialize() {return await this.dockerApi.connect();}@@ -164,7 +171,8 @@ class DockerCollector extends BaseCollector {const dockerPorts = await this._getDockerContainerPorts();dockerPorts.forEach((port) => {- const key = `${port.host_ip}:${port.host_port}:${port.protocol}`;+ const normalizedIp = this._normalizeHostIp(port.host_ip);+ const key = `${normalizedIp}:${port.host_port}:${port.protocol}`;if (!dockerPortsMap.has(key)) {if (port.container_id) {port.created = containerCreationTimeMap.get(port.container_id) || null;@@ -184,8 +192,9 @@ class DockerCollector extends BaseCollector {if (container.internalPorts && container.internalPorts.length > 0) {container.internalPorts.forEach((internalPort) => {- const publishedKey = `${internalPort.host_ip}:${internalPort.host_port}:${internalPort.protocol}`;- const internalKey = `${internalPort.host_ip}:${internalPort.host_port}:${internalPort.protocol}:${container.id}:internal`;+ const normalizedIp = this._normalizeHostIp(internalPort.host_ip);+ const publishedKey = `${normalizedIp}:${internalPort.host_port}:${internalPort.protocol}`;+ const internalKey = `${normalizedIp}:${internalPort.host_port}:${internalPort.protocol}:${container.id}:internal`;if (!dockerPortsMap.has(publishedKey) && !dockerPortsMap.has(internalKey)) {internalPort.created = containerCreationTimeMap.get(container.id) || null;@@ -203,7 +212,9 @@ class DockerCollector extends BaseCollector {const systemPorts = await this._getSystemPorts();for (const port of systemPorts) {- const key = `${port.host_ip}:${port.host_port}`;+ // Use same key format as docker ports for proper dedup+ const normalizedIp = this._normalizeHostIp(port.host_ip);+ const key = `${normalizedIp}:${port.host_port}:${port.protocol || 'tcp'}`;if (dockerPortsMap.has(key)) {continue;}@@ -301,10 +312,10 @@ class DockerCollector extends BaseCollector {const targetPort = parseInt(port, 10);for (const binding of hostBindings) {- const hostIp = binding.HostIp || '0.0.0.0';+ const hostIp = this._normalizeHostIp(binding.HostIp);const hostPort = parseInt(binding.HostPort, 10);- if (!hostIp || isNaN(hostPort)) continue;+ if (isNaN(hostPort)) continue;portEntries.push(this.normalizePortEntry({diff --git a/backend/collectors/truenas_collector.js b/backend/collectors/truenas_collector.jsindex 9967aa3..0a585ac 100644--- a/backend/collectors/truenas_collector.js+++ b/backend/collectors/truenas_collector.js@@ -570,8 +570,8 @@ class TrueNASCollector extends BaseCollector {* @returns {string} Resolved IP address*/_resolveHostIP(host_ip) {- if (host_ip === "0.0.0.0" || host_ip === "::") {- return host_ip;+ if (host_ip === "::" || host_ip === "[::]" || host_ip === "0.0.0.0") {+ return "0.0.0.0";}switch (host_ip) {@@ -1119,16 +1119,29 @@ class TrueNASCollector extends BaseCollector {await this._buildHostProcToContainerMap();for (const port of dockerPorts) {+ const normalizedIp = this._resolveHostIP(port.host_ip);++ if (port.internal && port.container_id) {+ const publishedKey = `${normalizedIp}:${port.host_port}`;+ const existingPort = uniquePorts.get(publishedKey);+ if (existingPort && existingPort.container_id === port.container_id) {+ continue;+ }+ }+const key = port.internal? `${port.container_id}:${port.host_port}:internal`- : `${port.host_ip}:${port.host_port}`;+ : `${normalizedIp}:${port.host_port}`;+ port.host_ip = normalizedIp;port.created =containerCreationTimeMap.get(port.container_id) || null;uniquePorts.set(key, port);}for (const port of systemPorts) {- const key = `${port.host_ip}:${port.host_port}`;+ const normalizedIp = this._resolveHostIP(port.host_ip);+ const key = `${normalizedIp}:${port.host_port}`;+ port.host_ip = normalizedIp;if (uniquePorts.has(key)) {const existingPort = uniquePorts.get(key);if (!existingPort.pid) existingPort.pid = port.pid;diff --git a/package.json b/package.jsonindex e389010..4aa51f2 100644--- a/package.json+++ b/package.json@@ -1,6 +1,6 @@{"name": "portracker",- "version": "1.3.1",+ "version": "1.3.2","description": "A multi-platform port-tracking dashboard","main": "backend/index.js","scripts": {