added --rooted --not-rooted flags to crawler
This commit is contained in:
		
							
								
								
									
										10
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								README.md
									
									
									
									
									
								
							@@ -96,7 +96,7 @@ Options:
 | 
				
			|||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### [crawler.js](./scripts/crawler.js)
 | 
					### [crawler.js](./scripts/crawler.js)
 | 
				
			||||||
**RAM:** 4.10 GB
 | 
					**RAM:** 4.15 GB
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Search the network for devices to execute a script against.
 | 
					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"].
 | 
					Running script with 1 thread(s), pid 1 and args: ["--help"].
 | 
				
			||||||
/scripts/crawler.js: 
 | 
					/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]...
 | 
					Usage:	run crawler.js [OPTIONS] SCRIPT [ARGS]...
 | 
				
			||||||
	run crawler.js --help
 | 
						run crawler.js --help
 | 
				
			||||||
@@ -116,8 +116,10 @@ Options:
 | 
				
			|||||||
	-c --cpu		 Number of CPU threads to use with script
 | 
						-c --cpu		 Number of CPU threads to use with script
 | 
				
			||||||
	-d --depth		 Depth to scan to, defaults to 3
 | 
						-d --depth		 Depth to scan to, defaults to 3
 | 
				
			||||||
	-l --level		 Exclude targets with higher hack level, defaults to current hack level
 | 
						-l --level		 Exclude targets with higher hack level, defaults to current hack level
 | 
				
			||||||
	-p --ports		 Exclute targets with too many closed ports
 | 
						-r --rooted		 Filter to devices that have been rooted
 | 
				
			||||||
	-s --silent		 Surpress program output
 | 
						-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
 | 
						-h --help		 Display this help message
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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: '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: '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: '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'}
 | 
							{name: 'silent', desc: 'Suppress program output', flags: ['-s', '--silent'], type: 'bool'}
 | 
				
			||||||
	], true);
 | 
						], true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -33,6 +35,11 @@ export async function main(ns) {
 | 
				
			|||||||
		const [devices, network] = scanNetwork(ns);
 | 
							const [devices, network] = scanNetwork(ns);
 | 
				
			||||||
		let complete = 0, failed = 0, skipped = 0;
 | 
							let complete = 0, failed = 0, skipped = 0;
 | 
				
			||||||
		for(let device of devices) {
 | 
							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
 | 
								// Skip invalid devices
 | 
				
			||||||
			if(device == 'home' || args['level'] < ns.getServerRequiredHackingLevel(device) || args['ports'] < ns.getServerNumPortsRequired(device)) {
 | 
								if(device == 'home' || args['level'] < ns.getServerRequiredHackingLevel(device) || args['ports'] < ns.getServerNumPortsRequired(device)) {
 | 
				
			||||||
				skipped++;
 | 
									skipped++;
 | 
				
			||||||
@@ -56,7 +63,7 @@ export async function main(ns) {
 | 
				
			|||||||
		// Output report
 | 
							// Output report
 | 
				
			||||||
		if(!args['silent']) {
 | 
							if(!args['silent']) {
 | 
				
			||||||
			ns.tprint('===================================================');
 | 
								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('===================================================');
 | 
				
			||||||
			ns.tprint(`Complete: ${complete}\tFailed: ${failed}\tSkipped: ${skipped}`);
 | 
								ns.tprint(`Complete: ${complete}\tFailed: ${failed}\tSkipped: ${skipped}`);
 | 
				
			||||||
			ns.tprint('');
 | 
								ns.tprint('');
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user