-
Notifications
You must be signed in to change notification settings - Fork 37
/
NimScan.nim
59 lines (44 loc) · 1.65 KB
/
NimScan.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#[
NimScan
https://github.com/elddy/NimScan
]#
when defined windows:
import modules/windows_sniffer
import modules/[globals, param_parser, scanner]
import os, net, nativesockets, times
proc main() =
## Main
var
hosts: seq[string]
ports: seq[int]
currentTime: int64
printBanner() ## Print banner
validateOpt(hosts, ports, timeout, maxThreads, file_discriptors_number)
when defined linux:
validateRlimit(file_discriptors_number)
currentTime = getTime().toUnix() ## Start time
if current_mode == mode.all:
## In filtered mode use rawsockets
printC(warning, "In rawsockets mode")
if ports.len > 10000 or file_discriptors_number > 5000:
printC(warning, "More than 10,000 ports or 5,000 file descriptors in raw sockets mode may produce unreliable results")
when defined windows:
add_rule() ## Add firewall rule for raw sockets
var
sniffer: Thread[SuperSocket]
supSocket: SuperSocket
for host in hosts:
supSocket = SuperSocket(IP: host, ports: ports)
createThread(sniffer, sniffer_thread, supSocket)
sleep(500)
startScanner(host, ports) ## Start scanning
when defined windows:
remove_rule() ## Remove firewall rule
else:
## In default mode use normal async scan
for host in hosts:
startScanner(host, ports) ## Start scanning
echo ""
printC(info, "NimScan finished in: " & $(getTime().toUnix() - currentTime) & " Seconds\n") ## End time
when isMainModule:
main()