lib/helpers.js
function getDefaultRoute() {
  try {
    const fileContents = fs.readFileSync('/proc/net/route', 'utf8'); // eslint-disable-line no-sync
    const routes = fileContents.split('\n');
    for (const routeIdx in routes) {
      const fields = routes[routeIdx].trim().split('\t');
      if (fields[1] === '00000000') {
        const address = fields[2];
        // Convert to little endian by splitting every 2 digits and reversing that list
        const littleEndianAddress = address.match(/.{2}/g).reverse().join('');
        return intToIP(parseInt(littleEndianAddress, 16));
      }
    }
  } catch (e) {
    console.error('Could not get default route from /proc/net/route');
  }
  return null;
}
function getDefaultRoute() {
  try {
    const fileContents = fs.readFileSync('/proc/net/route', 'utf8'); // eslint-disable-line no-sync
    const routes = fileContents.split('\n');
    for (const routeIdx in routes) {
      const fields = routes[routeIdx].trim().split('\t');
      if (fields[1] === '00000000') {
        const address = fields[2];
        // Convert to little endian by splitting every 2 digits and reversing that list
        const littleEndianAddress = address.match(/.{2}/g).reverse().join('');
        return intToIP(parseInt(littleEndianAddress, 16));
      }
    }
  } catch (e) {
    console.error('Could not get default route from /proc/net/route');
  }
  return null;
}
function getDefaultRoute ( ) { try { const fileContents = fs . readFileSync ( '/proc/net/route' , 'utf8' ) ; // eslint-disable-line no-sync const routes = fileContents . split ( '\n' ) ; for ( const routeIdx in routes ) { const fields = routes [ routeIdx ] . trim ( ) . split ( '\t' ) ; if ( fields [ 1 ] === '00000000' ) { const address = fields [ 2 ] ; // Convert to little endian by splitting every 2 digits and reversing that list const littleEndianAddress = address . match ( / .{2} / g ) . reverse ( ) . join ( '' ) ; return intToIP ( parseInt ( littleEndianAddress , 16 ) ) ; } } } catch ( e ) { console . error ( 'Could not get default route from /proc/net/route' ) ; } return null ; }
Returns the system default interface on Linux
Returns the system default interface on Linux