Skip to content
This repository was archived by the owner on Feb 24, 2026. It is now read-only.

Commit cf3b196

Browse files

File tree

1 file changed

+45
-40
lines changed

1 file changed

+45
-40
lines changed

src/scanner.mjs

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,45 @@ const getColor = (data, mode) => {
6363
}
6464
}
6565

66+
const createProcessConnection = (i) => {
67+
processList[i][0].on("message", (data) => {
68+
var x = assignedList.findIndex((sarray) => {
69+
const [number] = sarray
70+
return number === parseInt(data.thread)
71+
})
72+
if (data.status === "success") {
73+
currData.finds++
74+
currData.assigned--
75+
assignedList[x][1].finds++
76+
assignedList[x][1].assigned--
77+
assignedList[x][1].lastresponsetext = parseInt(Date.now()) - data.time
78+
assignedList[x][1].currentIp = data.ip
79+
var y = processList[assignedList[x][0]][1].findIndex((sarray) => {
80+
const [number] = sarray
81+
return number === data.ip
82+
})
83+
processList[assignedList[x][0]][1].splice(y, 1)
84+
logger.debug(processList[assignedList[x][0]][0].pid + " processed data from ip: " + assignedList[x][1].currentIp);
85+
}
86+
else if (data.status === "error") {
87+
currData.assigned--
88+
assignedList[x][1].assigned--
89+
assignedList[x][1].lastresponsetext = parseInt(Date.now()) - data.time
90+
assignedList[x][1].currentIp = data.ip
91+
var y = processList[assignedList[x][0]][1].findIndex((sarray) => {
92+
const [number] = sarray
93+
return number === data.ip
94+
})
95+
processList[assignedList[x][0]][1].splice(y, 1)
96+
logger.debug(processList[assignedList[x][0]][0].pid + " failed to processing ip: " + assignedList[x][1].currentIp);
97+
}
98+
else if (data.status === "ping") {
99+
assignedList[x][1].currentPings = 0
100+
logger.debug(processList[assignedList[x][0]][0].pid + " responded to ping request.")
101+
}
102+
})
103+
}
104+
66105
const Main = async () => {
67106
server.listen(servport, function () {
68107
console.log("Server listening on " + servport)
@@ -74,55 +113,20 @@ const Main = async () => {
74113
assignedList.push([i, { currentIp: "", lastresponsetext: 0, status: "Idle", assigned: 0, finds: 0, total: 0, currentPings: 0, restarts: 0 }])
75114
}
76115
for (var i = 0; i < processList.length; i++) {
77-
processList[i][0].on("message", (data) => {
78-
var x = assignedList.findIndex((sarray) => {
79-
const [number] = sarray
80-
return number === parseInt(data.thread)
81-
})
82-
if (data.status === "success") {
83-
currData.finds++
84-
currData.assigned--
85-
assignedList[x][1].finds++
86-
assignedList[x][1].assigned--
87-
assignedList[x][1].lastresponsetext = parseInt(Date.now()) - data.time
88-
assignedList[x][1].currentIp = data.ip
89-
var y = processList[assignedList[x][0]][1].findIndex((sarray) => {
90-
const [number] = sarray
91-
return number === data.ip
92-
})
93-
processList[assignedList[x][0]][1].splice(y, 1)
94-
logger.debug(processList[assignedList[x][0]][0].pid + " processed data from ip: " + assignedList[x][1].currentIp);
95-
}
96-
else if (data.status === "error") {
97-
currData.assigned--
98-
assignedList[x][1].assigned--
99-
assignedList[x][1].lastresponsetext = parseInt(Date.now()) - data.time
100-
assignedList[x][1].currentIp = data.ip
101-
var y = processList[assignedList[x][0]][1].findIndex((sarray) => {
102-
const [number] = sarray
103-
return number === data.ip
104-
})
105-
processList[assignedList[x][0]][1].splice(y, 1)
106-
logger.debug(processList[assignedList[x][0]][0].pid + " failed to processing ip: " + assignedList[x][1].currentIp);
107-
}
108-
else if (data.status === "ping") {
109-
assignedList[x][1].currentPings = 0
110-
logger.debug(processList[assignedList[x][0]][0].pid + " responded to ping request.")
111-
}
112-
})
116+
createProcessConnection(i)
113117
}
114118
console.log("Parser will be started in 3 seconds...")
115119
setTimeout(() => {
116120
startParser('java -Xmx5G -jar ' + process.cwd() + '/libs/copenJSParser-1.0-SNAPSHOT-5ms.jar')
117121
setInterval(async () => {
118122
assignedList.sort((a, b) => { return a[0] - b[0] })
119-
let defaultText = `Main Process: \n Current IP/s: ${currData.total - currData.totalLast} IP/s \n Total Assigned: ${currData.assigned} \n Total TCP Restarts: ${currData.tcpRestarts} \n Total Finds & Total Try: ${currData.finds} & ${currData.total} \n Current Rate: ${((currData.finds / currData.total) * 100).toFixed(2)}% \n Total Sub-Processes: ${currData.subprocesses} \n Current IP: ${currData.lastIp} \nSub-Processes: `
123+
let defaultText = `Main Process: \n Current IP/s: ${(currData.total - currData.totalLast) * 2} IP/s \n Total Assigned: ${currData.assigned} \n Total TCP Restarts: ${currData.tcpRestarts} \n Total Finds & Total Try: ${currData.finds} & ${currData.total} \n Current Rate: ${((currData.finds / currData.total) * 100).toFixed(2)}% \n Total Sub-Processes: ${currData.subprocesses} \n Current IP: ${currData.lastIp} \nSub-Processes: `
120124
assignedList.forEach(async (data, n) => {
121125
defaultText += "\n Process processNumber: Current IP: currentIP Last Response: lastResponseText Status: statusText Total Assigned: assignedInt Total Finds: findInt Restarts: restartInt Responseless Pings: pingInt ".replace("processNumber", n.toString()).replace("findInt", data[1].finds).replace("assignedInt", data[1].assigned).replace("currentIP", data[1].currentIp).replace("lastResponseText", `${getColor(data[1].lastresponsetext, "ms")}${data[1].lastresponsetext}ms\x1b[0m`).replace("statusText", `${getColor({ data: data[1].assigned, extra: data[1].currentPings }, "status")}\x1b[0m`).replace("restartInt", data[1].restarts).replace("pingInt", data[1].currentPings)
122126
})
123127
text.text = defaultText
124128
currData.totalLast = currData.total
125-
}, 1000)
129+
}, 500)
126130
setTimeout(() => {
127131
text.start()
128132
}, 1000)
@@ -146,10 +150,11 @@ const Main = async () => {
146150
assignedList[i][1].restarts++
147151
processList[assignedList[i][0]][1].shift()
148152
assignedList[i][1].assigned--
153+
currData.assigned--
154+
createProcessConnection(assignedList[i][0])
149155
processList[assignedList[i][0]][1].forEach((data) => {
150156
processList[assignedList[i][0]][0].send({ mode: "search", ip: data, time: Date.now() })
151157
processList[assignedList[i][0]][1].shift()
152-
assignedList[i][1].assigned--
153158
});
154159
assignedList[i][1].currentPings = 0
155160
}
@@ -161,7 +166,7 @@ const Main = async () => {
161166
socket.on('error', function (err) {
162167
console.log("Client lost connection")
163168
logger.warn("The client lost the connection " + err)
164-
startParser('java -Xmx5G -jar ' + process.cwd() + '/libs/copenJSParser-1.0-SNAPSHOT-5ms.jar "' + currData.lastIp + '"')
169+
startParser('java -Xmx5G -jar ' + process.cwd() + `/libs/copenJSParser-1.0-SNAPSHOT-5ms.jar "${process.cwd().split("src") + "scan.json"}" 0 "` + currData.lastIp + '"')
165170
currData.tcpRestarts++
166171
})
167172
socket.on('end', function () {

0 commit comments

Comments
 (0)