adsf
This commit is contained in:
parent
ee0bc5b5bf
commit
24a63f785b
|
|
@ -1,6 +1,11 @@
|
|||
import { NS } from '@ns';
|
||||
|
||||
export const main = async (ns: NS) => {
|
||||
if (ns.args.length !== 1) {
|
||||
ns.tprint('Usage: run super.js [target]');
|
||||
return;
|
||||
}
|
||||
|
||||
const target = ns.args[0].toString();
|
||||
|
||||
ns.tprint('Target selected: ' + target);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
import { NS } from '@ns';
|
||||
import { nuke } from './utils/nuke';
|
||||
import { scan } from './utils/scan';
|
||||
import { scriptPropagator } from './utils/script-propagator';
|
||||
|
||||
export const main = (ns: NS) => {
|
||||
const hosts = scan(ns, undefined, 50);
|
||||
ns.tprint(hosts);
|
||||
ns.tprint(scan(ns, { rootAccess: true }));
|
||||
scriptPropagator(ns);
|
||||
};
|
||||
|
|
|
|||
48
src/utils/nuke.ts
Normal file
48
src/utils/nuke.ts
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
import { NS } from '@ns';
|
||||
import { scan } from './scan';
|
||||
|
||||
// get root access to all the servers that we can
|
||||
// then return a list of all the servers we have root access to
|
||||
export const nuke = (ns: NS) => {
|
||||
// get a list of all hosts
|
||||
const allHosts: string[] = scan(ns);
|
||||
const newlyNukedHosts: string[] = [];
|
||||
|
||||
let alreadyNukedCount = 0;
|
||||
let newlyNukedCount = 0;
|
||||
let skippedCount = 0;
|
||||
|
||||
// attempt to nuke them all
|
||||
allHosts.forEach((host) => {
|
||||
// check if we already have root access to this host
|
||||
if (ns.hasRootAccess(host)) {
|
||||
alreadyNukedCount++;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
ns.nuke(host);
|
||||
|
||||
// Verification: Did it actually work?
|
||||
if (ns.hasRootAccess(host)) {
|
||||
ns.tprint(`Successfully nuked ${host}`);
|
||||
newlyNukedCount++;
|
||||
newlyNukedHosts.push(host);
|
||||
} else {
|
||||
ns.tprint(`Failed to nuke ${host} (Insufficient ports)`);
|
||||
skippedCount++;
|
||||
}
|
||||
} catch (error) {
|
||||
ns.tprint(`Error nuking ${host}: ${error}`);
|
||||
skippedCount++;
|
||||
}
|
||||
});
|
||||
|
||||
// print a summary of the results
|
||||
ns.tprint(`Already rooted: ${alreadyNukedCount}`);
|
||||
ns.tprint(`Newly rooted: ${newlyNukedCount}`);
|
||||
ns.tprint(`Skipped: ${skippedCount}`);
|
||||
|
||||
// scan again to get the list of all hosts we have root access to
|
||||
return newlyNukedHosts;
|
||||
};
|
||||
|
|
@ -1,12 +1,16 @@
|
|||
import { NS } from '@ns';
|
||||
|
||||
export const scan = (
|
||||
ns: NS,
|
||||
rootAccess?: boolean,
|
||||
requiredHackingSkill?: number,
|
||||
portsForNuke?: number,
|
||||
ram?: number,
|
||||
): string[] => {
|
||||
interface ScanOptions {
|
||||
rootAccess?: boolean;
|
||||
requiredHackingSkill?: number;
|
||||
portsForNuke?: number;
|
||||
ram?: number;
|
||||
}
|
||||
|
||||
export const scan = (ns: NS, options: ScanOptions = {}): string[] => {
|
||||
// destructure options
|
||||
const { rootAccess, requiredHackingSkill, portsForNuke, ram } = options;
|
||||
|
||||
// initialize a new set to store a list of all hosts
|
||||
const allHosts = new Set<string>(['home']);
|
||||
|
||||
|
|
@ -20,10 +24,11 @@ export const scan = (
|
|||
|
||||
// now we start the filtering into another new list
|
||||
const filteredHosts = Array.from(allHosts).filter((host: string) => {
|
||||
if (rootAccess && ns.hasRootAccess(host) !== rootAccess) return false;
|
||||
if (requiredHackingSkill && ns.getServerRequiredHackingLevel(host) > requiredHackingSkill) return false;
|
||||
if (portsForNuke && ns.getServerNumPortsRequired(host) > portsForNuke) return false;
|
||||
if (ram && ns.getServerMaxRam(host) < ram) return false;
|
||||
if (rootAccess !== undefined && ns.hasRootAccess(host) !== rootAccess) return false;
|
||||
if (requiredHackingSkill !== undefined && ns.getServerRequiredHackingLevel(host) > requiredHackingSkill)
|
||||
return false;
|
||||
if (portsForNuke !== undefined && ns.getServerNumPortsRequired(host) > portsForNuke) return false;
|
||||
if (ram !== undefined && ns.getServerMaxRam(host) < ram) return false;
|
||||
|
||||
return true;
|
||||
});
|
||||
|
|
|
|||
28
src/utils/script-propagator.ts
Normal file
28
src/utils/script-propagator.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import { NS } from '@ns';
|
||||
import { scan } from './scan';
|
||||
|
||||
export const scriptPropagator = (ns: NS) => {
|
||||
// get all hosts with root access
|
||||
const rootedHosts: string[] = scan(ns, { rootAccess: true });
|
||||
|
||||
// get all the script files, only the js files
|
||||
const allScripts: string[] = ns.ls('home', '.js');
|
||||
|
||||
let totalSynced = 0;
|
||||
|
||||
// iterate through all the rooted hosts and copy the scripts to them
|
||||
rootedHosts.forEach((host) => {
|
||||
try {
|
||||
ns.scp(allScripts, host);
|
||||
ns.tprint(`Synced scripts to ${host}`);
|
||||
totalSynced++;
|
||||
} catch (error) {
|
||||
ns.tprint(`Failed to sync scripts to ${host}: ${error}`);
|
||||
}
|
||||
});
|
||||
|
||||
ns.tprint(`Total hosts synced: ${totalSynced}`);
|
||||
|
||||
// return the list of rooted hosts for potential further use
|
||||
return rootedHosts;
|
||||
};
|
||||
Loading…
Reference in a new issue