added whitelist functionality

This commit is contained in:
2024-03-11 17:49:36 +01:00
parent 68494413bb
commit 4fdd0a7258
+8
View File
@@ -1,5 +1,10 @@
const whitelist = [
"127.0.0.1"
]
const net = require("net") const net = require("net")
const {exec} = require("child_process"); const {exec} = require("child_process");
const { ReadableStreamDefaultController } = require("node:stream/web");
const portlist = [21,1433] const portlist = [21,1433]
const host = "0.0.0.0"; const host = "0.0.0.0";
var ipSet = new Set() var ipSet = new Set()
@@ -14,6 +19,9 @@ portlist.forEach(i => {
}) })
// defining connection event // defining connection event
server.on("connection", a => { server.on("connection", a => {
// if the ip is in the whitelist, ignore the connection (this is to prevent manually crafted packets to)
if(whitelist.includes(a.remoteAddress)) return
console.log(`incomming connection from : ${a.remoteAddress} on port ${i}`) console.log(`incomming connection from : ${a.remoteAddress} on port ${i}`)
// handle error even on socket instance (prevents the econnreset error) // handle error even on socket instance (prevents the econnreset error)
a.on("error", () => {}) a.on("error", () => {})