@opsimathically/nmap
v0.0.1
Published
TypeScript controller and XML parser wrapper for Linux nmap.
Downloads
19
Maintainers
Readme
NMAP
TypeScript wrapper for driving Linux nmap scans, capturing XML output, and parsing into
typed objects.
Features
- Programmatically run
nmapwith arbitrary arguments and target lists. - Enforce XML stdout mode (
-oX -) and return raw XML. - Parse XML reports into strongly typed objects (via
fast-xml-parser). - Map parsed reports to arbitrary app-specific shapes.
- Optional
sudomodes for privileged scans:nonekeyboard(interactive terminal password input)programmatic(password piped viasudo -S)
- Timeout and abort-signal support.
Install
npm install @opsimathically/nmapBasic scan
import { NMAPProcessController } from '@opsimathically/nmap';
const nmap_controller = new NMAPProcessController();
const scan_result = await nmap_controller.runScan({
scan_request: {
targets: ['127.0.0.1'],
nmap_args: ['-sV'],
sudo_mode: 'none'
}
});
console.log(scan_result.exit_code);
console.log(scan_result.stdout_xml);
console.log(scan_result.parsed_report?.hosts);Keyboard sudo mode
import { NMAPProcessController } from '@opsimathically/nmap';
const nmap_controller = new NMAPProcessController();
const scan_result = await nmap_controller.runScan({
scan_request: {
targets: ['scanme.nmap.org'],
nmap_args: ['-sS'],
sudo_mode: 'keyboard'
}
});
console.log(scan_result.parsed_report?.hosts.length);Programmatic sudo mode
import { NMAPProcessController } from '@opsimathically/nmap';
const nmap_controller = new NMAPProcessController();
const scan_result = await nmap_controller.runScan({
scan_request: {
targets: ['scanme.nmap.org'],
nmap_args: ['-sS'],
sudo_mode: 'programmatic',
sudo_password: process.env.NMAP_SUDO_PASSWORD
}
});
console.log(scan_result.stderr);Map parsed XML into custom objects
import { NMAPProcessController } from '@opsimathically/nmap';
const nmap_controller = new NMAPProcessController();
const mapped_result = await nmap_controller.runScanAndMap({
scan_request: {
targets: ['127.0.0.1'],
nmap_args: ['-sV'],
sudo_mode: 'none'
},
map_report: ({ report }) => {
return report.hosts.map((host) => ({
host: host.addresses[0]?.addr,
open_ports: host.ports
.filter((port) => port.state?.state === 'open')
.map((port) => port.portid)
}));
}
});
console.log(mapped_result.mapped_report);Build from source
npm install
npm run buildTest
npm test