UNPKG

node-red-contrib-network-tools

Version:

Comprehensive network monitoring and discovery tools for Node-RED with Bonjour/mDNS support

228 lines (210 loc) 10.6 kB
<script type="text/javascript"> RED.nodes.registerType('network-discovery', { category: 'brdc-network-nodes', color: '#FF6D00', defaults: { name: {value: ""}, subnet: {value: "192.168.1.0/24", validate: function(v) { return v && (v.includes('/') || v.includes('-') || /^([0-9]{1,3}\.){3}[0-9]{1,3}$/.test(v)); }}, portRange: {value: "22,80,443"}, timeout: {value: 3000, validate: RED.validators.number()}, concurrent: {value: 10, validate: RED.validators.number()}, includeHostnames: {value: false}, includePorts: {value: false}, includeBonjourServices: {value: false}, bonjourServiceTypes: {value: "http,ssh,ftp,smb"}, bonjourTimeout: {value: 5000, validate: RED.validators.number()} }, inputs: 1, outputs: 1, icon: "inject.png", label: function() { return this.name || "network-discovery"; }, oneditprepare: function() { $("#node-input-includePorts").change(function() { if ($(this).is(':checked')) { $("#port-range-row").show(); } else { $("#port-range-row").hide(); } }).trigger('change'); $("#node-input-includeBonjourServices").change(function() { if ($(this).is(':checked')) { $("#bonjour-service-types-row").show(); $("#bonjour-timeout-row").show(); } else { $("#bonjour-service-types-row").hide(); $("#bonjour-timeout-row").hide(); } }).trigger('change'); } }); </script> <script type="text/html" data-template-name="network-discovery"> <div class="form-row"> <label for="node-input-name"><i class="icon-tag"></i> Name</label> <input type="text" id="node-input-name" placeholder="Name"> </div> <div class="form-row"> <label for="node-input-subnet"><i class="fa fa-sitemap"></i> Subnet</label> <input type="text" id="node-input-subnet" placeholder="192.168.1.0/24 or 192.168.1.1-192.168.1.50"> <div class="form-tips">CIDR notation (192.168.1.0/24), range (192.168.1.1-50), or single IP</div> </div> <div class="form-row"> <label for="node-input-timeout"><i class="fa fa-clock-o"></i> Timeout (ms)</label> <input type="number" id="node-input-timeout" min="500" max="10000"> </div> <div class="form-row"> <label for="node-input-concurrent"><i class="fa fa-tasks"></i> Concurrent</label> <input type="number" id="node-input-concurrent" min="1" max="50"> <div class="form-tips">Number of simultaneous ping operations</div> </div> <div class="form-row"> <label for="node-input-includeHostnames"><i class="fa fa-tag"></i> Include Hostnames</label> <input type="checkbox" id="node-input-includeHostnames"> <div class="form-tips">Perform reverse DNS lookup for discovered hosts</div> </div> <div class="form-row"> <label for="node-input-includePorts"><i class="fa fa-plug"></i> Include Port Scan</label> <input type="checkbox" id="node-input-includePorts"> <div class="form-tips">Scan common ports on discovered hosts</div> </div> <div class="form-row" id="port-range-row"> <label for="node-input-portRange"><i class="fa fa-list"></i> Port Range</label> <input type="text" id="node-input-portRange" placeholder="22,80,443 or 80-90"> <div class="form-tips">Comma-separated ports or ranges (e.g., 22,80,443 or 80-90,443)</div> </div> <div class="form-row"> <label for="node-input-includeBonjourServices"><i class="fa fa-search"></i> Include Bonjour/mDNS</label> <input type="checkbox" id="node-input-includeBonjourServices"> <div class="form-tips">Discover services using Bonjour/mDNS (zero-configuration networking)</div> </div> <div class="form-row" id="bonjour-service-types-row"> <label for="node-input-bonjourServiceTypes"><i class="fa fa-cogs"></i> Service Types</label> <input type="text" id="node-input-bonjourServiceTypes" placeholder="http,ssh,ftp,smb"> <div class="form-tips">Comma-separated service types to discover (e.g., http,ssh,ftp,smb,printer)</div> </div> <div class="form-row" id="bonjour-timeout-row"> <label for="node-input-bonjourTimeout"><i class="fa fa-clock-o"></i> Bonjour Timeout (ms)</label> <input type="number" id="node-input-bonjourTimeout" min="1000" max="30000"> <div class="form-tips">How long to wait for Bonjour service responses</div> </div> </script> <script type="text/html" data-help-name="network-discovery"> <p>Discovers active devices on a network subnet with optional hostname resolution and port scanning.</p> <h3>Inputs</h3> <dl class="message-properties"> <dt class="optional">subnet <span class="property-type">string</span></dt> <dd>Network subnet to scan (overrides configuration)</dd> <dt class="optional">portRange <span class="property-type">string</span></dt> <dd>Ports to scan on discovered hosts</dd> <dt class="optional">timeout <span class="property-type">number</span></dt> <dd>Timeout in milliseconds for each ping</dd> <dt class="optional">concurrent <span class="property-type">number</span></dt> <dd>Number of concurrent ping operations</dd> <dt class="optional">includeHostnames <span class="property-type">boolean</span></dt> <dd>Whether to perform reverse DNS lookups</dd> <dt class="optional">includePorts <span class="property-type">boolean</span></dt> <dd>Whether to scan ports on discovered hosts</dd> <dt class="optional">includeBonjourServices <span class="property-type">boolean</span></dt> <dd>Whether to discover services using Bonjour/mDNS</dd> <dt class="optional">bonjourServiceTypes <span class="property-type">string</span></dt> <dd>Comma-separated list of service types to discover</dd> <dt class="optional">bonjourTimeout <span class="property-type">number</span></dt> <dd>Timeout in milliseconds for Bonjour service discovery</dd> </dl> <h3>Outputs</h3> <dl class="message-properties"> <dt>payload <span class="property-type">object</span></dt> <dd>Discovery report with found devices and scan statistics</dd> </dl> <h3>Features</h3> <ul> <li><strong>Subnet Scanning:</strong> CIDR notation (/24), IP ranges (1.1.1.1-50), or single IPs</li> <li><strong>Concurrent Processing:</strong> Configurable parallel ping operations</li> <li><strong>Hostname Resolution:</strong> Optional reverse DNS lookups</li> <li><strong>Port Scanning:</strong> Check common services on discovered hosts</li> <li><strong>Bonjour/mDNS Discovery:</strong> Zero-configuration service discovery (.local hostnames, service advertisements)</li> <li><strong>Progress Tracking:</strong> Real-time status updates during scan</li> <li><strong>Flexible Configuration:</strong> Override settings via input messages</li> </ul> <h3>Configuration</h3> <p><strong>Name:</strong> Optional name for the node</p> <p><strong>Subnet:</strong> Network subnet to scan. Supports:</p> <ul> <li>CIDR notation: <code>192.168.1.0/24</code></li> <li>IP range: <code>192.168.1.1-192.168.1.50</code> or <code>192.168.1.1-50</code></li> <li>Single IP: <code>192.168.1.1</code></li> </ul> <p><strong>Timeout:</strong> Maximum wait time per ping in milliseconds (500-10000)</p> <p><strong>Concurrent:</strong> Number of parallel ping operations (1-50)</p> <p><strong>Add Hostnames:</strong> Perform reverse DNS lookup for discovered hosts</p> <p><strong>Add Port Scan:</strong> Scan common ports on active hosts</p> <p><strong>Port Range:</strong> Specify ports to scan (e.g., 22,80,443 or 80-90,443)</p> <p><strong>Include Bonjour/mDNS:</strong> Discover services using zero-configuration networking</p> <p><strong>Service Types:</strong> Bonjour service types to discover (e.g., http,ssh,ftp,smb,printer)</p> <p><strong>Bonjour Timeout:</strong> Maximum wait time for service discovery (1000-30000ms)</p> <h3>Example Output</h3> <pre>{ "subnet": "192.168.1.0/24", "totalHosts": 254, "aliveHosts": 12, "bonjourServicesFound": 8, "scanDuration": "2024-01-01T00:00:00.000Z", "devices": [ { "ip": "192.168.1.1", "alive": true, "responseTime": 1.2, "hostname": "router.local", "openPorts": [22, 80, 443], "bonjourServices": [ { "name": "Router Web Interface", "type": "http", "protocol": "tcp", "host": "router.local", "port": 80, "fqdn": "router._http._tcp.local" } ], "serviceTypes": ["http"], "bonjourServiceCount": 1, "timestamp": "2024-01-01T00:00:00.000Z" } ], "bonjourServices": [ { "name": "John's MacBook", "type": "ssh", "protocol": "tcp", "host": "Johns-MacBook.local", "port": 22, "addresses": ["192.168.1.100"] } ], "scanOptions": { "portRange": "22,80,443", "timeout": 3000, "includeHostnames": true, "includePorts": true, "includeBonjourServices": true, "bonjourServiceTypes": ["http", "ssh", "ftp", "smb"] } }</pre> <h3>Use Cases</h3> <ul> <li>Network inventory and asset discovery</li> <li>Security monitoring and unauthorized device detection</li> <li>Network documentation and mapping</li> <li>Service availability monitoring</li> <li>IoT device discovery and management</li> </ul> <h3>Security Considerations</h3> <p><strong>Note:</strong> Use this node only on networks where you have permission to scan. Unauthorized network scanning may be considered a security threat.</p> <h3>Performance Tips</h3> <ul> <li>Limit the number of concurrent operations to reduce network load</li> <li>Use lower timeouts for faster scans of local networks</li> <li>Enable hostname resolution only when needed (slows down the scan)</li> <li>Limit port ranges to necessary services</li> </ul> </script>