Advertisement
Guest User

Untitled

a guest
Sep 8th, 2019
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. export async function main(ns) {
  2.     let queue = [];
  3.     let visited = {};
  4.    
  5.     bft(ns);
  6. }
  7.  
  8. function bft(ns) {
  9.     let graph = {};
  10.     let graphviz = ""
  11.     let q = [...ns.scan(ns.getHostname())];
  12.     let visited = {};
  13.     let vertex;
  14.     while (q.length > 0) {
  15.         vertex = q.shift();
  16.         // ns.tprint(q);
  17.         if (!visited[vertex]) {
  18.             visited[vertex] = true;
  19.             graph[vertex] = ns.scan(vertex).map(item => {
  20.                 graphviz += `\n\t"${vertex}" -> "${item}"`
  21.                 return item
  22.             });
  23.             q = [...q, ...ns.scan(vertex)];
  24.         }
  25.     }
  26.    
  27.     graphviz = `digraph G{ \n${graphviz} \n}`
  28.  
  29.     ns.write("map.txt", `${JSON.stringify(graph)}`,"w");
  30.     ns.write("graphviz.txt", graphviz ,"w");
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement