n8n-nodes-nmap
Version:
Nmap Scan
100 lines • 4.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.NmapUtils = void 0;
class NmapUtils {
parseNmapQuickScan(output) {
let results = [];
const lines = output.split('\n').filter((line) => line.trim() !== '');
for (let i = 0; i < lines.length; i++) {
let newDevice = {};
const regex = /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/;
const match = lines[i].match(regex);
if (match !== null) {
newDevice['ip'] = match[0].trim();
for (let y = i; y < lines.length; y++) {
if (lines[y].includes('MAC Address:')) {
const macRegex = /([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})/;
const macMatch = lines[y].match(macRegex);
if (macMatch !== null) {
newDevice['mac'] = macMatch[0].trim();
}
const nameRegex = /\((.*?)\)/;
const nameMatch = lines[y].match(nameRegex);
if (nameMatch !== null) {
newDevice['name'] = nameMatch[1].trim();
}
results.push(newDevice);
i = y--;
break;
}
}
}
}
return results;
}
parseNmapDiscovery(output, ports_field) {
let results = [];
const lines = output.split('\n').filter((line) => line.trim() !== '');
for (let i = 0; i < lines.length; i++) {
let newDevice = {};
const regex = /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/;
const match = lines[i].match(regex);
if (match !== null) {
newDevice['ip'] = match[0].trim();
while (!lines[i].includes('PORT')) {
i++;
}
const portRegex = /(\d+\/\w+)\s+(\w+)\s+(.+)/;
const portResult = [];
for (let y = i + 1; y < lines.length; y++) {
const portMatch = lines[y].match(portRegex);
if (portMatch !== null) {
let newPort = {};
newPort['port'] = portMatch[1].trim();
newPort['state'] = portMatch[2].trim();
newPort['service'] = portMatch[3].trim();
portResult.push(newPort);
}
else {
newDevice[ports_field] = portResult;
i = y - 1;
break;
}
}
for (let y = i; y < lines.length; y++) {
if (lines[y].includes('MAC Address:')) {
const macRegex = /([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})/;
const macMatch = lines[y].match(macRegex);
if (macMatch !== null) {
newDevice['mac'] = macMatch[0].trim();
}
const nameRegex = /\((.*?)\)/;
const nameMatch = lines[y].match(nameRegex);
if (nameMatch !== null) {
newDevice['name'] = nameMatch[1].trim();
}
results.push(newDevice);
i = y - 1;
break;
}
}
}
}
return results;
}
parseNmapPorts(output) {
let results = [];
const regex = /(\d+\/\w+)\s+(\w+)\s+(.+)/g;
let match;
while ((match = regex.exec(output)) !== null) {
let newPort = {};
newPort['port'] = match[1].trim();
newPort['state'] = match[2].trim();
newPort['service'] = match[3].trim();
results.push(newPort);
}
return results;
}
}
exports.NmapUtils = NmapUtils;
//# sourceMappingURL=NmapUtils.js.map