added --rooted --not-rooted flags to crawler

This commit is contained in:
Zakary Timson 2022-03-20 13:42:49 -04:00
parent 65050fb619
commit de7eb3bc4f
2 changed files with 15 additions and 6 deletions

View File

@ -96,7 +96,7 @@ Options:
```
### [crawler.js](./scripts/crawler.js)
**RAM:** 4.10 GB
**RAM:** 4.15 GB
Search the network for devices to execute a script against.
```
@ -104,7 +104,7 @@ Search the network for devices to execute a script against.
Running script with 1 thread(s), pid 1 and args: ["--help"].
/scripts/crawler.js:
Search the network for devices to execute a script against.
Search the network for targets to execute a script against.
Usage: run crawler.js [OPTIONS] SCRIPT [ARGS]...
run crawler.js --help
@ -116,8 +116,10 @@ Options:
-c --cpu Number of CPU threads to use with script
-d --depth Depth to scan to, defaults to 3
-l --level Exclude targets with higher hack level, defaults to current hack level
-p --ports Exclute targets with too many closed ports
-s --silent Surpress program output
-r --rooted Filter to devices that have been rooted
-n --not-rooted Filter to devices that have not been rooted
-p --ports Exclude targets with too many closed ports
-s --silent Suppress program output
-h --help Display this help message
```

View File

@ -23,7 +23,9 @@ export async function main(ns) {
{name: 'cpu', desc: 'Number of CPU threads to use with script', flags: ['-c', '--cpu'], default: 1, type: 'num'},
{name: 'depth', desc: 'Depth to scan to, defaults to 3', flags: ['-d', '--depth'], default: Infinity, type: 'num'},
{name: 'level', desc: 'Exclude targets with higher hack level, defaults to current hack level', flags: ['-l', '--level'], default: ns.getHackingLevel(), type: 'num'},
{name: 'ports', desc: 'Exclute targets with too many closed ports', flags: ['-p', '--ports'], default: Infinity, type: 'num'},
{name: 'rooted', desc: 'Filter to devices that have been rooted', flags: ['-r', '--rooted'], type: 'bool'},
{name: 'notRooted', desc: 'Filter to devices that have not been rooted', flags: ['-n', '--not-rooted'], type: 'bool'},
{name: 'ports', desc: 'Exclude targets with too many closed ports', flags: ['-p', '--ports'], default: Infinity, type: 'num'},
{name: 'silent', desc: 'Suppress program output', flags: ['-s', '--silent'], type: 'bool'}
], true);
@ -33,6 +35,11 @@ export async function main(ns) {
const [devices, network] = scanNetwork(ns);
let complete = 0, failed = 0, skipped = 0;
for(let device of devices) {
// Check root status if needed
const rooted = ns.hasRootAccess(device);
if(args['rooted'] && !rooted) continue;
if(args['notRooted'] && rooted) continue;
// Skip invalid devices
if(device == 'home' || args['level'] < ns.getServerRequiredHackingLevel(device) || args['ports'] < ns.getServerNumPortsRequired(device)) {
skipped++;
@ -56,7 +63,7 @@ export async function main(ns) {
// Output report
if(!args['silent']) {
ns.tprint('===================================================');
ns.tprint(`Crawler Report: ${devices.length} Device${devices.length > 1 ? 's' : ''}`);
ns.tprint(`Crawler Report: ${complete + failed + skipped} Devices`);
ns.tprint('===================================================');
ns.tprint(`Complete: ${complete}\tFailed: ${failed}\tSkipped: ${skipped}`);
ns.tprint('');