Bitburner

Bitburner

View Stats:
Softshine798 Dec 24, 2023 @ 12:24pm
Scripting Question
So far, I am enjoying the game, but overwhelmed by the amount of options there are for scripting. I have read the officiaal beginner guide[bitburner.readthedocs.io] so far and think I'm doing fine, but I still would not know how to create a new script from scratch. One script that I did want to create was one that automatically opens all ports on a server (ie BruteSSH.exe, FTPCrack.exe...), and then runs a NUKE on it. I would not know how to get it running, is the problem.

I would like to be able to get a script running that at the very least runs all of the port opening executables, and then runs NUKE.exe on it, just by running the script in the terminal, either by running it when connected to the server, or just pass the name of the server I want to hack as a paramater.
< >
Showing 1-15 of 21 comments
Softshine798 Dec 24, 2023 @ 2:03pm 
Best guess so far for the script would be:

var target = args[0] if (fileExists("BruteSSH.exe", "home")) { brutessh(target); } if (fileExists("FTPCrack.exe", "home")) { ftpcrack(target); } //Repeat same logic for other three files. nuke(target);

EDIT: So far, the code does work, but I do not know the names for the other three files, and I would also like to backdoor into the server.
Last edited by Softshine798; Dec 24, 2023 @ 2:07pm
Croak Dec 24, 2023 @ 2:11pm 
This will nuke ever server you're able to.

export async function main(ns) { ns.scan("home").forEach(disseminate); function disseminate(target) { if (ns.fileExists("BruteSSH.exe", "home")) { ns.brutessh(target); } if (ns.fileExists("FTPCrack.exe", "home")) { ns.ftpcrack(target); } if (ns.fileExists("relaySMTP.exe", "home")) { ns.relaysmtp(target); } if (ns.fileExists("HTTPWorm.exe", "home")) { ns.httpworm(target); } if (ns.fileExists("SQLInject.exe", "home")) { ns.sqlinject(target); } try { ns.nuke(target); } catch (ex) { } ns.scan(target).slice(1).forEach(disseminate); } }
Last edited by Croak; Dec 25, 2023 @ 11:09am
Softshine798 Dec 24, 2023 @ 2:18pm 
Originally posted by Croak:
This will nuke ever server you're able to.

export async function main(ns) { ns.scan("home").forEach(disseminate); function disseminate(target) { if (ns.fileExists("BruteSSH.exe", "home")) { ns.brutessh(target); } if (ns.fileExists("FTPCrack.exe", "home")) { ns.ftpcrack(target); } if (ns.fileExists("relaySMTP.exe", "home")) { ns.relaysmtp(target); } if (ns.fileExists("HTTPWorm.exe", "home")) { ns.httpworm(target); } if (ns.fileExists("SQLInject.exe", "home")) { ns.sqlinject(target); } ns.nuke(target); ns.scan(target).slice(1).forEach(disseminate); } }
For this, is this a .script file, or .js file. And how much RAM would it cost to run in game?
Softshine798 Dec 24, 2023 @ 7:59pm 
And now I am trying to improve the augment script form the beginning to use a a script I made for auto-breaching, but I'mg etting an error with passing an object instead of a string.

for (var i = 0; i < servers2Port.length; ++i) { var serv = servers1Port;

scp("early-hack-template.script", serv);
run("autobreach.script", 1, serv)
exec("early-hack-template.script", serv, 24);
}
//autobreach.script


var target = args

if (fileExists("BruteSSH.exe", "home")) {
brutessh(target);
}
if (fileExists("FTPCrack.exe", "home")) {
ftpcrack(target);
}
if (fileExists("relaySMTP.exe", "home")) {
relaysmtp(target);
}
if (fileExists("SQLInject.exe", "home")) {
sqlinject(target);
}
if (fileExists("HTTPWorm.exe", "home")) {
httpworm(target);
}

nuke(target);[/code]

.
Last edited by Softshine798; Dec 25, 2023 @ 6:51pm
Bugs Bunny Dec 25, 2023 @ 2:38am 
First, swtich to .js files/code ASAP, .script isn't supported anymore. Still works, but it's just bad in every way.

About the last piece of code you shared:

1. You're copying your auto-breach to other servers. This is not necessary since the port crackers and nuke both take the server name as a parameter, so you can crack/nuke all the ports/servers from a single script on home. One of the things that will break your logic is some servers do not have ram... even if they might be hackable.
2. nuke can crash the script if there isn't enough ports open, so you need a try/catch around it (in js only, script doesn't need/support it)
3. The hardcoded 24 you give for threads on the early hack template will fail on a lot of servers, you need to check the script ram and the server free ram to figure how many threads you can use

Otherwise you're in the right path. Look at the script Croak posted, it's decent
Croak Dec 25, 2023 @ 11:10am 
Originally posted by The Manager:
2. nuke can crash the script if there isn't enough ports open, so you need a try/catch around it (in js only, script doesn't need/support it)
I edited my original script to include the try catch, forgot that detail.

Originally posted by Softshine798:
For this, is this a .script file, or .js file. And how much RAM would it cost to run in game?

It's javascript, 2.2GB RAM cost.
Last edited by Croak; Dec 25, 2023 @ 11:21am
Softshine798 Dec 25, 2023 @ 2:47pm 
Originally posted by The Manager:
First, swtich to .js files/code ASAP, .script isn't supported anymore. Still works, but it's just bad in every way.

About the last piece of code you shared:

1. You're copying your auto-breach to other servers. This is not necessary since the port crackers and nuke both take the server name as a parameter, so you can crack/nuke all the ports/servers from a single script on home. One of the things that will break your logic is some servers do not have ram... even if they might be hackable.
2. nuke can crash the script if there isn't enough ports open, so you need a try/catch around it (in js only, script doesn't need/support it)
3. The hardcoded 24 you give for threads on the early hack template will fail on a lot of servers, you need to check the script ram and the server free ram to figure how many threads you can use

Otherwise you're in the right path. Look at the script Croak posted, it's decent
On the topic of JavaScript, how does aliasing work for the scripts for Bitburner?
Softshine798 Dec 25, 2023 @ 6:47pm 
And sorry for double post, but I had some more questions.

https://github.com/kamukrass/Bitburner I am currently looking at this page for some scripts, and I am currently looking at the grow one they have:

export async function main(ns) { await ns.sleep(ns.args[1]); const server = ns.args[0]; if (ns.args.length >= 3) { await ns.grow(server, { stock: ns.args[2] }); } else { await ns.grow(server); } }
I was able to get this to repeat forever by nesting it within a while loop, but I cannot get it to get more than one argument. I will admit that I have zero Javascript experience, but I do have up to CS1 knowlege with J*va, C#, and Python (trying to branch to data structures with Python), so I'm kind of a bit lost.

Best guess to get the grow script to be able to work on several different servers is to:
-pass an array/list/etc, or just a bunch of strings, as an argument(s)
-stick a conditional inside the grow function to oscilate between the arguments, and use modulus on a variable to keep looping bewteen the servers
I was thinking something like this:

servers = ['joesguns', 'n00dles', 'silver-helix', 'FBI', 'CIA']
i = 0
while i < 100:
print(servers[i % len(servers)])
i += 1


This was written in Python, and I was able to test out the logic in IDLE. but I would not know how to implement this with Javascript and the in-game logic.

EDIT: One last question: For running each script (hack, grow, and weaken) on a single server, what would the ratio for hack:grow:weaken be?

Initially, I tried 25% hacking, 25% growth, and 50% weaken, but I immediately ran out of money. I then changed it to 10% hacking, 40% growth, and 50% weaken, and issue still persisted.

I imagine the biggest bottlneck is excessive weaken because the security level is always very low.
Last edited by Softshine798; Dec 25, 2023 @ 8:08pm
Croak Dec 26, 2023 @ 11:37am 
I admittedly do not know what the additional arguments for hack/grow/weaken do as I didn't bother digging in that deep. I just separate my grow scripts and my hack scripts to conditionally hack/grow/weaken depending on the status of the server I pass in as an argument. You can use the hackAnalyze and growthAnalyze methods to determine how much of an effect a single threaded hack/grow will have, and from there it's basic math. I believe the sweet spot is roughly 34% from a post I read that was a couple years old. So you could say for example targetServerCash / (hackAnalyze(target) * targetServerCash) * .333 = totalHackThreads. I believe hackAnalyze returns a fraction of the money available rather than a monetary value hence the multiplication. growthAnalyze is similar but you pass it the multiplier you want the available money to be increased by and it gives you the total threads necessary, so if you left the server with 66.7% of it's maximum money after a hack cycle, you'd want a grow multiplier of 50% to get it back to 100%. It's worth noting the analyze functions only take into account the server's current status, so you'd have to unlock the Formulas API in the game to get access to the functions that let you spoof a server at specific thresholds for the most accurate calculations. Until you have that the safest bet is to grow and weaken everything you target first THEN deploy your long term hack/grow scripts, threading them as needed for each given server.

If you're attempting to hack servers with only a single thread you're not going to see any money flow. Until you've upgraded your computer/bought additional servers like the ingame beginner guide teaches you, hacking income is going to be vastly outpaced by crimes in the city slums.

The grow function you found is intended to be used alongside a manager that passes in a target and a sleep time to make it execute immediately after a growth cycle, then terminate to maximize RAM availability. If you're struggling with writing scripts, I wouldn't try to tackle a manager that advanced yet. Just set up something that loops and figures out what to do at runtime with conditionals until you're comfortable enough to tackle that timing aspect.
Last edited by Croak; Dec 26, 2023 @ 11:52am
Softshine798 Dec 27, 2023 @ 5:21am 
/** @param {NS} ns */ export async function main(ns) { var serv = ns.args[0] var target = ns.args[1] ns.scp("hack-loop.js", serv); ns.scp("weaken-loop.js", serv); ns.scp("grow-loop.js", serv); //RAM usage is split up between functions with 2^14 GBs ns.exec("hack-loop.js", serv, 1446, target); //1.7GB RAM; 15% allocated ns.exec("weaken-loop.js", serv, 3276, target); //1.75GB RAM; 35% allocated ns.exec("grow-loop.js", serv, 4681, target); //1.75GB RAM; 50% allocated } }

So far, this is what I have to copy/paste servers, with the percentages being for RAM used:
15% hack
35 % weaken
50 % grow

And for each of the individual loops:

export async function main(ns) { await ns.sleep(0); const server = ns.args[0]; while (true){ await ns.hack(server); } } }

export async function main(ns) { await ns.sleep(0); while(true){ await ns.weaken(ns.args[0]); } }

export async function main(ns) { await ns.sleep(0); const server = ns.args[0]; while (true){ await ns.grow(server); } }
Croak Dec 27, 2023 @ 7:22am 
Seems like a good balance if you're not initially growing the servers. You can go into the Active Scripts tab and open the log on your hack-loop.js for each execution to see how much it's actually taking on each execution. You can use ns.print() to get extra info each cycle, but by default ns.hack will write the current wait time and how much was taken after each cycle, as well as exp rewarded.
Softshine798 Dec 27, 2023 @ 9:06am 
Originally posted by Croak:
Seems like a good balance if you're not initially growing the servers. You can go into the Active Scripts tab and open the log on your hack-loop.js for each execution to see how much it's actually taking on each execution. You can use ns.print() to get extra info each cycle, but by default ns.hack will write the current wait time and how much was taken after each cycle, as well as exp rewarded.

Looking into my hack.js for most of them, and it's consistently hacking sub million costs, if not zero dollars. For all of the servers I hacked when I was idling when sleeping, only two of them actually had a decent amount of money hacked (alpha-ent with $11bil, then syscore with $85bil) over the course of 4 hours.

I think that I have too much weight in hack, and possibly in weaken, in some of them, too. As an example, with rho-construction, I'm always getting grow results within the tens of millions(percentage wise) and every weaken is bringing it down to the minimum security level, but with the hacking, when it actually does hack money, I'm only getting around $300k/hack, immediately for the money to be drained. Over 3.25 hours, the hack only yielded $2.95bil.
Croak Dec 27, 2023 @ 9:44am 
Originally posted by Softshine798:
Looking into my hack.js for most of them, and it's consistently hacking sub million costs, if not zero dollars. For all of the servers I hacked when I was idling when sleeping, only two of them actually had a decent amount of money hacked (alpha-ent with $11bil, then syscore with $85bil) over the course of 4 hours.

I think that I have too much weight in hack, and possibly in weaken, in some of them, too. As an example, with rho-construction, I'm always getting grow results within the tens of millions(percentage wise) and every weaken is bringing it down to the minimum security level, but with the hacking, when it actually does hack money, I'm only getting around $300k/hack, immediately for the money to be drained. Over 3.25 hours, the hack only yielded $2.95bil.
It sounds like either you're hacking when the server is empty/near empty or when the security is too high so the hack fails. I'd heavily suggest adding these to your hack scripts even though it'll increase the ram cost per thread so you can better understand what the bottleneck is. You can place them inside a print and/or use them in a conditional to tell the hack to wait until server cash is maxed and security is minimized.

ns.getServerSecurityLevel(target);
ns.getServerMinSecurityLevel(target);
ns.getServerMoneyAvailable(target);
ns.getServerMaxMoney(target);

I'd also suggest combining the weaken scripts with both the hack scripts and the grow scripts instead. When you're not using a manager to min-max execution times, the RAM cost is actually higher to separate them. Every script has a base cost of 1.6GB. Weaken and grow are both only 0.15, and hack is just 0.10. Just set them both to weaken if the server security is more than whatever threshold you're comfortable with (I think I go with 5 points over minimum myself) else hack/grow. You could also tell hack to only hack when money's maxed out, but given the ratio you provided earlier that shouldn't matter unless hack is executing more than twice as fast as each grow.
Last edited by Croak; Dec 27, 2023 @ 9:52am
Softshine798 Dec 27, 2023 @ 9:51am 
Originally posted by Croak:
Originally posted by Softshine798:
Looking into my hack.js for most of them, and it's consistently hacking sub million costs, if not zero dollars. For all of the servers I hacked when I was idling when sleeping, only two of them actually had a decent amount of money hacked (alpha-ent with $11bil, then syscore with $85bil) over the course of 4 hours.

I think that I have too much weight in hack, and possibly in weaken, in some of them, too. As an example, with rho-construction, I'm always getting grow results within the tens of millions(percentage wise) and every weaken is bringing it down to the minimum security level, but with the hacking, when it actually does hack money, I'm only getting around $300k/hack, immediately for the money to be drained. Over 3.25 hours, the hack only yielded $2.95bil.
It sounds like either you're hacking when the server is empty/near empty or when the security is too high so the hack fails. I'd heavily suggest adding these to your hack scripts even though it'll increase the ram cost per thread so you can better understand what the bottleneck is. You can place them inside a print and/or use them in a conditional to tell the hack to wait until server cash is maxed and security is minimized.

ns.getServerSecurityLevel(target);
ns.getServerMinSecurityLevel(target);
ns.getServerMoneyAvailable(target);
ns.getServerMaxMoney(target);
Both are occuring, but the former case is the bigger problem for me.

I've also been experimenting with the syscore, since I was beginning to have a problem, too, albeit smaller.


Running 6981 threads for grow, 1639 for weaken, and 555 for hack.
Croak Dec 27, 2023 @ 9:53am 
You responded while I was writing the following edit, so just to prevent you from missing it:

I'd also suggest combining the weaken scripts with both the hack scripts and the grow scripts instead. When you're not using a manager to min-max execution times, the RAM cost is actually higher to separate them. Every script has a base cost of 1.6GB. Weaken and grow are both only 0.15, and hack is just 0.10. Just set them both to weaken if the server security is more than whatever threshold you're comfortable with (I think I go with 5 points over minimum myself) else hack/grow. You could also tell hack to only hack when money's maxed out, but given the ratio you provided earlier that shouldn't matter unless hack is executing more than twice as fast as each grow.

Originally posted by Softshine798:
Both are occuring, but the former case is the bigger problem for me.

I've also been experimenting with the syscore, since I was beginning to have a problem, too, albeit smaller.


Running 6981 threads for grow, 1639 for weaken, and 555 for hack.
I almost guarantee your hacks are outpacing your grows in that case. Add in a conditional to only hack above a given server money threshold and that'll fix your primary issue.
Last edited by Croak; Dec 27, 2023 @ 9:55am
< >
Showing 1-15 of 21 comments
Per page: 1530 50