Bitburner

Bitburner

35 ratings
Basic Auto Farm for beginners
By PG SDVX
Simple auto farm script that can be used to learn some basics
3
   
Award
Favorite
Favorited
Unfavorite
Prologue and code
The guide is pretty much in the code section with my attempt at documentation
It's completely plug and play :D
This is best used for learning, and not for quality farming, go to my Intermediate guide if you want a serious upgrade


disableLog("ALL"); tail(); clearLog();//Just for visual clarity in the console

// Welcome to my messy, horribly optimised, quickly slapped together script for beginners, by a beginner, good luck with this brain aneurysm which I tried to document
// This whole thing will scan for all servers you can hack, then start automatically farming them, but it's not the fastest

var files = ["weak.script", "grow.script", "hack.script"]; //These are the files will be sent with 'scp' to target servers later

//This part will show a yes/no prompt, with yes creating/overwriting the 3 files listed above, and no will stop the script
if (prompt("This will overwrite any files in your home directory named weak.script, grow.script and hack.script, click yes to allow or no to exit")){
write(files[0], "weaken(args)", "w"); write(files[1], "grow(args)", "w"); write(files[2], "hack(args)", "w")
} else {exit()}

//Sets variables, I wouldn't touch them, might explode
var serverList = scan("home"); var serverCount = [serverList.length, 0];
var hk = [0, 0, 0, 0, 0]; var scanLevel = 2;var approvedList = [];
var index = 0; var inner = 0; var exeCount = 0; var hackType;
var linked; var target; var depth = 0; var checked = 0;

//Checks if you have hacks so we know for later
if (fileExists("BruteSSH.exe")) { hk[0] = 1; exeCount++ };
if (fileExists("FTPCrack.exe")) { hk[1] = 1; exeCount++ };
if (fileExists("relaySMTP.exe")) { hk[2] = 1; exeCount++ };
if (fileExists("HTTPWorm.exe")) { hk[3] = 1; exeCount++ };
if (fileExists("SQLInject.exe")) { hk[4] = 1; exeCount++ };
if (fileExists("DeepscanV1.exe")) { scanLevel += 2 }; //Comment out one or both of these lines if you don't have
if (fileExists("DeepscanV2.exe")) { scanLevel += 5 }; //high hack skill or want to avoid time consuming deep scans

//The badly formatted fun begins...
print("/=====/ SEARCHING \\=====\\\n|----| Scans to L" + [scanLevel + 1] + "\n| L1 | "+ serverList.join("\n| L1 | ")) //Print is just for the visuals
while (index <= serverCount[depth] - 1 && depth < scanLevel) {//The scan will stop if we hit depth limit
linked = scan(serverList[checked]);checked++; //Scan will bring back all connected servers which we then run through checks below
for (i = 0; i <= linked.length - 1; i++) {//If the scan results in 1 or more linked servers this area will cycle through them
target = linked[i];//Targets 1 part of the scan result at a time
if (target != "home" && !serverList.includes(target)) {//Makes sure our target isn't home or a server we already know of
serverList.push(target);//Adds the target to the list
print("| L"+ [depth + 2] + " | " + target); serverCount[depth + 1]++;
}
}
if (index == serverCount[depth] - 1) { index = 0; depth++; serverCount.push(0) } else { index++ };//Increases index if there are still servers in this depth level,
} //resets index and goes one level deeper if there isn't

print("/==========/ CHECKING \\==========\\");
for (i = 0; i <= serverList.length - 1; i++) {//Runs once for each entry in serverList
target = serverList[i];
if (getServerNumPortsRequired(target) > exeCount) { print("| X HACKS | " + target) } //Denied if you cannot open enough ports
else if (getServerMoneyAvailable(target) == 0) { print("| X MONEY | " + target) } //Denied if there's no loot
else if (getServerMaxRam(target) < 2) { print("| X 0 RAM | " + target) } //Denied because potato
else if (getHackingLevel() < getServerRequiredHackingLevel(target)) { print("| X SKILL | " + target) } //Denied because your hacking is too low
else {//Server approved, 5 lines below will open ports on target if you have the required exe
if (hk[0]) { brutessh(target) };
if (hk[1]) { ftpcrack(target) };
if (hk[2]) { relaysmtp(target) };
if (hk[3]) { httpworm(target) };
if (hk[4]) { sqlinject(target) };
nuke(target); scp(files, "home", target); killall(target);//Nuke, transfer files and kill running scripts on target
approvedList.push(target);//This server is ready to farm, puts it in the approved list for later
print("| > VALID | " + target);
}
}

print("/=======/ HACKING \\=======\\");
index = 0;//Reset so we can use it again
while (true) {//Runs forever
if (index > approvedList.length - 1) { index = 0 }//Sets index to 0 if we reach the end of list, starts cycle again
target = approvedList[index];//Picks server from list based on index
if (getServerUsedRam(target) == 0) { //If nothing is already running on server
if (getServerSecurityLevel(target) > getServerMinSecurityLevel(target) + 5) { hackType = "weak" } //and the security is too high, weaken /You can change the 5
else if (getServerMoneyAvailable(target) < getServerMaxMoney(target) * 0.70) { hackType = "grow" }//and the money is too low, boosto /and the 0.80
else { hackType = "hack" }; //and if everything is just right...
print("| " + hackType + " | " + approvedList[index]);
exec(hackType + ".script", target, Math.floor(getServerMaxRam(target) / getScriptRam(hackType + ".script")), target)//Runs 1 of the 3 scripts on target server against itself
} index++;//Helps us cycle through our list || Threads are maxed out based on the amount of RAM the server has divided by how much RAM the script takes to run, rounded down
}
//Do note that with lots of "approved servers" this will not be optimal, at all, this is just a lazy way to do things at the start
//With very little thought you could make the scripts run against a different target too, hope you find this mess even slightly helpful, and have a good day :)
22 Comments
Kermit 10 Jun, 2024 @ 4:11pm 
disableLog("ALL"); tail(); clearLog();//Just for visual clarity in the console

// Welcome to my messy, horribly optimised, quickly slapped together script for beginners, by a beginner, good luck with this brain aneurysm which I tried to document
// This whole thing will scan for all servers you can hack, then start automatically farming them, but it's not the fastest
Playmaking Shot Creator 11 Apr, 2022 @ 8:01pm 
can i get a link to the new script
Papa 19 Dec, 2021 @ 4:07am 
????????????
PG SDVX  [author] 19 Dec, 2021 @ 1:16am 
New script is available! Check it out if you want much higher gains than this
PG SDVX  [author] 18 Dec, 2021 @ 6:55pm 
Updated based on feedback that my documentation for creating the mini scripts was confusing
The 3 extra scripts will auto install themselves after a prompt, 100% plug and play now!
A new and much more advanced script is coming very soon, but with a lot less documentation
PG SDVX  [author] 18 Dec, 2021 @ 5:32pm 
Thank you for the explanation toku, I'm often stuck thinking of the best way to say something :slimetabby:
tokumeiko 18 Dec, 2021 @ 5:21pm 
powertoys that code isn't as hard to make, but you'd want to also change the criteria for approving servers, since we just need ram and ports to be available for running code, you also can't run as many attacks though since this would turn every available server against a single target.
PowerToys 18 Dec, 2021 @ 11:22am 
As i understand the code (im a beginner so i might be wrong) this script uses var target at all points, that means it just runs hack/weak/grow no every server against itself.

What if i want it to run all servers on same target? use it as a swarm attack against a single server? wouldn't it be batter? this way each grow/weak function would take fraction of the time as you would have more combined threads and ram per attack?
tokumeiko 18 Dec, 2021 @ 7:27am 
just realised that you can make it more efficient by splitting the victim servers array according to how many hacker servers are available, and making each hacker server responsible for managing a smaller number of victims.
and for a more advanced farming we can have a small script wait for certain thresholds in skill and money, then buy a bunch of 8gb servers (the smallest that can run your script), then all the hackers and wait for the victims to finish their last instruction before we repopulate the server list based on the new values.