UNPKG

node-red-contrib-network-tools

Version:
162 lines (148 loc) 7.5 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} }, 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'); } }); </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> </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> </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>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> <h3>Example Output</h3> <pre>{ "subnet": "192.168.1.0/24", "totalHosts": 254, "aliveHosts": 12, "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], "timestamp": "2024-01-01T00:00:00.000Z" } ], "scanOptions": { "portRange": "22,80,443", "timeout": 3000, "includeHostnames": true, "includePorts": true } }</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>