index.js
async function searchPrevRoutes(target) {
    const connNames = await listConnectionNames();
    const ret = [];
    for (const connName of connNames) {
        const cmd = [
            'nmcli', '-f', 'IP4.ROUTE', 'connection', 'show', connName,
        ];
        const output = await executeCommand(cmd);
        for (const line of output.split('\n')) {
            const exs = `dst\\s*=\\s*${target},\\snh\\s*=\\s*([\\d\.]+)`;
            const re = line.match(new RegExp(exs));
            if (!re) {
                continue;
            }
            ret.push({
                connName: connName,
                target: target,
                gatewayIP: re[1],
            });
        }
    }
    return ret;
}
async function searchPrevRoutes(target) {
    const connNames = await listConnectionNames();
    const ret = [];
    for (const connName of connNames) {
        const cmd = [
            'nmcli', '-f', 'IP4.ROUTE', 'connection', 'show', connName,
        ];
        const output = await executeCommand(cmd);
        for (const line of output.split('\n')) {
            const exs = `dst\\s*=\\s*${target},\\snh\\s*=\\s*([\\d\.]+)`;
            const re = line.match(new RegExp(exs));
            if (!re) {
                continue;
            }
            ret.push({
                connName: connName,
                target: target,
                gatewayIP: re[1],
            });
        }
    }
    return ret;
}
async function searchPrevRoutes ( target ) { const connNames = await listConnectionNames ( ) ; const ret = [ ] ; for ( const connName of connNames ) { const cmd = [ 'nmcli' , '-f' , 'IP4.ROUTE' , 'connection' , 'show' , connName , ] ; const output = await executeCommand ( cmd ) ; for ( const line of output . split ( '\n' ) ) { const exs = ` \\ \\ ${ target } \\ \\ \\ \\ \. ` ; const re = line . match ( new RegExp ( exs ) ) ; if ( ! re ) { continue ; } ret . push ( { connName : connName , target : target , gatewayIP : re [ 1 ] , } ) ; } } return ret ; }
Search previous route from NetworkManager
@param {string} target : the destination network or host. e.g. 224.0.23.0/32
@return {Array.<object>} Return list of previous route setting
Search previous route from NetworkManager