Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export async function main(ns) {
- let queue = [];
- let visited = {};
- bft(ns);
- }
- function bft(ns) {
- let graph = {};
- let graphviz = ""
- let q = [...ns.scan(ns.getHostname())];
- let visited = {};
- let vertex;
- while (q.length > 0) {
- vertex = q.shift();
- // ns.tprint(q);
- if (!visited[vertex]) {
- visited[vertex] = true;
- graph[vertex] = ns.scan(vertex).map(item => {
- graphviz += `\n\t"${vertex}" -> "${item}"`
- return item
- });
- q = [...q, ...ns.scan(vertex)];
- }
- }
- graphviz = `digraph G{ \n${graphviz} \n}`
- ns.write("map.txt", `${JSON.stringify(graph)}`,"w");
- ns.write("graphviz.txt", graphviz ,"w");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement