Skip to content

Instantly share code, notes, and snippets.

@YPetremann
Last active June 20, 2016 10:20
Show Gist options
  • Save YPetremann/6b5a3d9eb258472f552ebd70915682e2 to your computer and use it in GitHub Desktop.
Save YPetremann/6b5a3d9eb258472f552ebd70915682e2 to your computer and use it in GitHub Desktop.
Hacknet Netmap Organise to Grid
#!/usr/bin/python
import sys
import re
import random
from math import ceil, floor
def fround(num, places = 0, direction = round):
return direction(num * (10**places)) / float(10**places)
# path of the save you want organized
file = sys.argv[1]
# table of network elements (cols and rows are inverted)
netmap = [
["bitMission01" ,"bitMission02" ,"" ,"ppMarketing" ,"milburgHigh" ,"xcTablet" ],
["jscottHome" ,"macrosoftWorkhorse04","honeypot01" ,"producerComp" ,"entropy01" ,"entropy01.1" ],
["" ,"" ,"entropy00" ,"themeHackTransComp","lelzSecHub" ,"pacemakerSW_BE" ],
["pacemaker01" ,"entropyAdvFail01" ,"netEduComp" ,"polarSnake" ,"psTrial01" ,"psTrial02" ],
["bitDropBox" ,"bitRelay01" ,"psTrial04" ,"polarSnakeDest" ,"hubPubDrop" ,"hubCrossroads" ],
["haxServer" ,"BitWorkServer" ,"webReddit" ,"practiceServer" ,"clockServer" ,"miscMacrosoftStorage"],
["EnTechOfflineBackup","porthackHeart" ,"firstGeneratedNode","eosTest2" ,"bitMission00" ,"boatmail" ],
["themeHackComp" ,"eosIntroComp" ,"playerComp" ,"psTrial03" ,"test01" ,"mainHub" ],
["naixGateway" ,"eosAdded1Comp" ,"eosIntroPhone" ,"psTrial03b" ,"kellisHW_BE" ,"mainHubAssets" ],
["eosAddedPhone" ,"hubTestComp02" ,"hubTestComp03" ,"nortronMail" ,"nortronInternalServices","kellisHW" ],
["hubTestComp01" ,"viperScanEarlyGame" ,"portcrack01" ,"portcrack01_eos" ,"nortronMainframe" ,"nortronWebServer" ],
["enPrometheus_eos2" ,"enPrometheus_eos1" ,"kfcWebServer" ,"kfcMainframe" ,"SecuLockHome" ,"secuLockDrive" ],
["EnTechPrometheus" ,"EnTechOutsiderRepo" ,"EnTechRomulus" ,"kfcRecordsRepo" ,"decSoftMainframe" ,"SecuLockHome_eos" ],
["enMail" ,"EnTechMainframe" ,"EnWS03" ,"academic" ,"jmail" ,"decSoftWeb" ],
["EnTechWeb" ,"EnTechWSCore" ,"EnWS01" ,"creditsComp" ,"medical" ,"salEosPhone" ],
["EnWS04" ,"EnWS05" ,"EnWS02" ,"ispComp" ,"deathRow" ,"hubEosMisison" ]
]
content = open(file).read()
# Get nodes
nodes = re.findall("<computer[^>]*id=\"([^\"]*)\"",content)
random.shuffle(nodes)
# Get size
lines = 6.0
columns = len(nodes)/6.0
while len(netmap) < columns:
netmap.append(["","","","","",""])
# Remove already placed nodes
for col in netmap:
if col is not None:
for node in col:
if node is not None:
if node in nodes:
nodes.remove(node)
print "\t".join(nodes)
# insert nodes in table
for col in netmap:
if col is not None:
for node in col:
if node is not None:
if node == "":
col[col.index("")]=nodes.pop()
print
print "\t".join(nodes)
# replace nodes in file
for col in netmap:
if col is not None:
x = fround(netmap.index(col) / float(len(netmap)-1), 3, floor)
for node in col:
if node is not "":
y = fround(col.index(node) / float(len(col)-1), 3, floor)
try:
index = re.search("id=\""+node+"\"", content, 1).start()
content = content[:index] + re.sub("<location x=\"[^\"]*\" y=\"[^\"]*\" />", "<location x=\""+str(x)+"\" y=\""+str(y)+"\" />", content[index:], 1)
# print("[ OK ]",node, x, y)
except Exception as e:
print("[ FAIL ]",node, x, y, e)
open(file,"w").write(content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment