source/lib/VBDiscover.js
// Send an ECP request to each potential host on the network

Send an ECP request to each potential host on the network
Send an ECP request to each potential host on the network
function subnetScan(discoveryCallback, hostLimit = 256) {
  const interfaceList = os.networkInterfaces()
  for (let interfaceListEntry of Object.values(interfaceList)) {
    for (let interfaceItem of Object.values(interfaceListEntry)) {
      if (!interfaceItem.internal && interfaceItem.family === 'IPv4') {
        const ip32 = ipAddrTo32(interfaceItem.address)
        const mask32 = ipAddrTo32(interfaceItem.netmask)
        if (ip32 > 0 && mask32 > 0) {
          const maxHosts = (2 ** 32) - mask32
          const lastHost = maxHosts > hostLimit ? hostLimit : maxHosts
          const base32 = ip32 - (ip32 % maxHosts)
          for (let i = 1; i < lastHost - 1; i++) {
            const host32 = base32 + i
            if (host32 !== ip32) {
              const ipAddr = ip32ToAddr(host32)
              deviceDiscovered(ipAddr, '', discoveryCallback)
            }
          }
        }
      }
    }
  }
}
function subnetScan ( discoveryCallback , hostLimit = 256 ) { const interfaceList = os . networkInterfaces ( ) for ( let interfaceListEntry of Object . values ( interfaceList ) ) { for ( let interfaceItem of Object . values ( interfaceListEntry ) ) { if ( ! interfaceItem . internal && interfaceItem . family === 'IPv4' ) { const ip32 = ipAddrTo32 ( interfaceItem . address ) const mask32 = ipAddrTo32 ( interfaceItem . netmask ) if ( ip32 > 0 && mask32 > 0 ) { const maxHosts = ( 2 ** 32 ) - mask32 const lastHost = maxHosts > hostLimit ? hostLimit : maxHosts const base32 = ip32 - ( ip32 % maxHosts ) for ( let i = 1 ; i < lastHost - 1 ; i ++ ) { const host32 = base32 + i if ( host32 !== ip32 ) { const ipAddr = ip32ToAddr ( host32 ) deviceDiscovered ( ipAddr , '' , discoveryCallback ) } } } } } } }
Send an ECP request to each potential host on the network
Send an ECP request to each potential host on the network
// Get the list of all network interfaces
 // Examine each network interface
 // Get the list of IP addresses handled by this interface
 // Only handle non-internal (not loopback), IPv4 addresses
 // Convert the interface ip address and subnet mask
 // from dotted decimal to 32-bit integers
 // Only continue if the ip address and subnet mask are valid
 // Use the subnet mask to determine the maximum number of
 // hosts to scan for on this subnet
 // Limit the maximum number of hosts addressed
 // Compute the base address for all hosts on this subnet
 // Scan each host on this subnet (don't scan first and last)
 // Generate next host ip address
 // Don't send an ECP request to ourself
 // Send an ECP request to the host ip address
