Im trying to get ip address from netstat -a using a script on nodejs with regex, but im unable to solve this problem.
Regex seems to be unable to return value from the output file from netstat.
Here is the code:
const { spawn } = require("child_process");
const fs = require("fs");
const netstat = spawn("netstat", ["-n", ">", `D:/iplookup/out.txt`]);
const regex = /^([0-255]{1-3}\.)(3)[0-255]:[0-9]{1-4}*$/g;
const re = new RegExp(regex);
netstat.on("close", () => {
    fs.readFile("D:/iplookup/out.txt", "utf8", (error, data) => {
        if(error) {
            console.log(error);
        }
        var m = [];
        dt = data.replace(/(\r\n|\n|\r)/gm, "");
        console.log(re.test(dt));
        do {
            m.push(dt.matchAll(re));
        } while (dt.match(re));
        console.log(m)
    });
});
Thanks.
 
    