index.js
async function searchConnNameFromIP(ip) { // eslint-disable-line no-unused-vars
    const connNames = await listConnectionNames();
    const gipnum = ipv4.convToNum(ip);
    for (const connName of connNames) {
        const cmd = [
            'nmcli', '-f', 'IP4.ADDRESS', 'connection', 'show', connName,
        ];
        const output = await executeCommand(cmd);
        for (const line of output.split('\n')) {
            const re = line.match(/\s+([\d\.]+)\/([\d]+)/);
            if (!re) {
                continue;
            }
            const ip = ipv4.convToNum(re[1]);
            const mask = parseInt(re[2]);
            if ((ip & mask) == (gipnum & mask)) {
                return connName;
            }
        }
    }
    return null;
}
async function searchConnNameFromIP(ip) { // eslint-disable-line no-unused-vars
    const connNames = await listConnectionNames();
    const gipnum = ipv4.convToNum(ip);
    for (const connName of connNames) {
        const cmd = [
            'nmcli', '-f', 'IP4.ADDRESS', 'connection', 'show', connName,
        ];
        const output = await executeCommand(cmd);
        for (const line of output.split('\n')) {
            const re = line.match(/\s+([\d\.]+)\/([\d]+)/);
            if (!re) {
                continue;
            }
            const ip = ipv4.convToNum(re[1]);
            const mask = parseInt(re[2]);
            if ((ip & mask) == (gipnum & mask)) {
                return connName;
            }
        }
    }
    return null;
}
async function searchConnNameFromIP ( ip ) { // eslint-disable-line no-unused-vars const connNames = await listConnectionNames ( ) ; const gipnum = ipv4 . convToNum ( ip ) ; for ( const connName of connNames ) { const cmd = [ 'nmcli' , '-f' , 'IP4.ADDRESS' , 'connection' , 'show' , connName , ] ; const output = await executeCommand ( cmd ) ; for ( const line of output . split ( '\n' ) ) { const re = line . match ( / \s+([\d\.]+)\/([\d]+) / ) ; if ( ! re ) { continue ; } const ip = ipv4 . convToNum ( re [ 1 ] ) ; const mask = parseInt ( re [ 2 ] ) ; if ( ( ip & mask ) == ( gipnum & mask ) ) { return connName ; } } } return null ; }
Search the connection name of the same network from the ip address
@param {string} ip : ip address
@return {string} connection name for NetworkManager
Search the connection name of the same network from the ip address