-
Notifications
You must be signed in to change notification settings - Fork 3
/
portscanner.r
29 lines (26 loc) · 856 Bytes
/
portscanner.r
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
# prompt the user for the host and range of ports to scan
host <- readline(" [*] Enter the host to scan: ")
port_range <- readline(" [*] Enter the range of ports to scan (e.g. '1-1024'): ")
# parse the port range input
port_range <- as.integer(strsplit(port_range, "-")[[1]])
port_range <- port_range[1]:port_range[2]
# create a function to check if a port is open
check_port <- function(port) {
conn <- socketConnection(host = host, port = port, server = FALSE, timeout = 2)
if(class(conn) == "socketConnection") {
close(conn)
return(TRUE)
} else {
return(FALSE)
}
}
# scan the ports and print the results
cat(" [*] Scanning ports on", host, "...\n")
for(port in port_range) {
if(check_port(port)) {
cat(" [+] Port", port, "is open.\n")
} else {
cat(" [-] Port", port, "is closed.\n")
}
}
cat(" [*] Scan complete.\n")