TaxenHeimer/nimscan/scanner.nim
2022-07-26 01:37:50 -04:00

54 lines
1.3 KiB
Nim

import std/[random, strutils, os, net, locks, httpclient, json]
proc status(targetIP: string): bool {.gcsafe.}=
var client = newSocket()
try:
client.connect(targetIP, Port(25565), 1500)
client.send($((char)0xFE))
if (client.recv(256, 1000)[0] == (char)0xFF):
return true
except Exception:
return false
finally:
client.close()
proc GenerateIP(): string {.gcsafe.} =
randomize()
var
ip0 = rand(255)
ip1 = rand(255)
ip2 = rand(255)
ip3 = rand(255)
return (join([$ip0, $ip1, $ip2, $ip3], "."))
proc hit(host: string) {.gcsafe.} =
echo "[+] Hit on ", host
var client = newHttpClient()
try:
client.headers = newHttpHeaders({"Content-Type": "application/json"})
let body = %*{
"server": host
}
let res = client.request("http://localhost:9000/server", HttpPost, $body)
discard res
except Exception as e:
echo e.msg
discard
proc main(): void {.thread.} =
while true:
var ip = GenerateIP()
var ping = status(ip)
if ping:
hit(ip)
discard
var cmd = os.execShellCmd("clear")
var cLock: Lock
initLock(cLock)
var thread: Thread[void]
for i in 0..300:
createThread[void](thread, main)
joinThreads(thread)