Skip to content

Instantly share code, notes, and snippets.

@Summertime
Last active December 31, 2021 16:26
Show Gist options
  • Save Summertime/7d467707e2dfd794277475c53281b985 to your computer and use it in GitHub Desktop.
Save Summertime/7d467707e2dfd794277475c53281b985 to your computer and use it in GitHub Desktop.
bitburner scripts
function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array
}
/** @param {NS} ns **/
export async function main(ns) {
let args = ns.flags([
['name', ''],
])
let hosts = args._.slice(0)
if (hosts.length === 0)
exit()
shuffleArray(hosts)
while (true)
for (const host of hosts)
await ns.grow(host)
}
function allhosts(ns) {
let hosts = ['home'];
for (const host of hosts)
for (const newhost of ns.scan(host))
if (!hosts.includes(newhost))
hosts.push(newhost)
return hosts
}
/** @param {NS} ns **/
export async function main(ns) {
const player = ns.getPlayer()
const targets = allhosts(ns)
.slice(1)
.map(h => ns.getServer(h))
.filter(s => s.hasAdminRights)
.filter(s => s.requiredHackingSkill <= player.hacking)
ns.scriptKill('growloop.js', 'home')
ns.scriptKill('secloop.js', 'home')
let X = 0
while (X++ < 8) {
ns.exec('growloop.js', 'home', 4, '--name', X, ...targets.map(h => h.hostname))
ns.exec('secloop.js', 'home', 4, '--name', X, ...targets.map(h => h.hostname))
}
}
function allhosts(ns) {
let hosts = ['home'];
for (const host of hosts)
for (const newhost of ns.scan(host))
if (!hosts.includes(newhost))
hosts.push(newhost)
return hosts
}
/** @param {NS} ns **/
export async function main(ns) {
const player = ns.getPlayer()
const hosts = allhosts(ns)
for (const host of hosts) {
ns.scriptKill('hackloop.js', host)
}
const servers = hosts.map(h => ns.getServer(h))
const sources = servers.slice(1).filter(s => s.hasAdminRights)
const targets = sources.filter(s => s.requiredHackingSkill <= player.hacking)
for (const source of sources) {
await ns.scp('hackloop.js', 'home', source.hostname)
const freeRam = source.maxRam - source.ramUsed;
const neededRam = ns.getScriptRam('hackloop.js', source.hostname)
const threads = Math.floor(freeRam / neededRam)
if (threads > 0)
ns.exec('hackloop.js', source.hostname, threads, ...targets.map(s => s.hostname))
}
}
function allhosts(ns) {
let hosts = ['home'];
for (const host of hosts)
for (const newhost of ns.scan(host))
if (!hosts.includes(newhost))
hosts.push(newhost)
return hosts
}
/** @param {NS} ns **/
export async function main(ns) {
const openers = {
ftp: ns.fileExists('FTPCrack.exe', 'home'),
http: ns.fileExists('HTTPWorm.exe', 'home'),
smtp: ns.fileExists('relaySMTP.exe', 'home'),
sql: ns.fileExists('SQLInject.exe', 'home'),
ssh: ns.fileExists('BruteSSH.exe', 'home'),
}
const numOpenPorts = Object.values(openers).reduce((a, b) => a + b)
const rootable = allhosts(ns)
.slice(1)
.map(h => ns.getServer(h))
.filter(s => !s.hasAdminRights)
.filter(s => s.numOpenPortsRequired <= numOpenPorts)
for (const server of rootable) {
if (openers.ftp)
ns.ftpcrack(server.hostname)
if (openers.http)
ns.httpworm(server.hostname)
if (openers.smtp)
ns.relaysmtp(server.hostname)
if (openers.sql)
ns.sqlinject(server.hostname)
if (openers.ssh)
ns.brutessh(server.hostname)
ns.nuke(server.hostname)
}
}
function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array
}
/** @param {NS} ns **/
export async function main(ns) {
let args = ns.flags([
['name', ''],
])
let hosts = args._.slice(0)
if (hosts.length === 0)
exit()
shuffleArray(hosts)
while (true)
for (const host of hosts)
await ns.weaken(host)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment