import os from 'os' ; const platform = os . platform ( ) ; function getInterfaceName ( ) { let val = 'eth' ; if ( platform === 'darwin' ) { val = 'en' ; } else if ( platform === 'win32' ) { val = null ; } return val ; } function getInterface ( family ) { const interfaces = os . networkInterfaces ( ) ; const name = getInterfaceName ( ) ; family = family || 'IPv4' ; for ( let i = - 1 ; i < 8 ; i ++ ) { const interfaceName = `${ name }${ i >= 0 ? i : '' }` ; const items = interfaces [ interfaceName ] ; if ( items ) { for ( let j = 0 , len = items . length ; j < len ; j ++ ) { const item = items [ j ] ; if ( item . family === family ) { return item ; } } } } for ( const k in interfaces ) { const items = interfaces [ k ] ; if ( items ) { for ( let i = 0 , len = items . length ; i < len ; i ++ ) { const item = items [ i ] ; if ( item . family === family && item . address !== '127.0.0.1' ) { return item ; } } } } return ; } /**
 * Get current machine IPv4
 */ function ip ( ) { const item = getInterface ( 'IPv4' ) ; return item && item . address ; } export default { ip } ;