forked from greedalbadi/ReaperProgram
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrscan.py
74 lines (74 loc) · 2.46 KB
/
rscan.py
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import subprocess
import threading
import requests
import socket
from prettytable import PrettyTable
import os
from getmac import get_mac_address
class Scan_info:
shell = True
Prot = "http://"
RDP_port = 3389
SSH_port = 22
class Ip_range_scanner:
def __init__(self):
self.os = os.name
self.Activethreads = 0
self.table = PrettyTable(["Address", "Hostname", "Browser", "RDP", "MAC", "SSH"])
def portscan(self, target, port):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(3)
conn = s.connect_ex((target, port))
if (conn == 0):
return True
else:
return False
def command(self, ip):
if self.os == "nt":
return f"ping {ip} -n 1"
else:
return f"ping {ip} -c 1"
def Getmac(self, ip):
address = get_mac_address(ip=ip)
if address == None:
return "Not Found"
else:
return address
def scanner(self, ip, rang):
print("Scanning network..")
ip = ip[:-1]
for ran in range(int(rang)):
new_ip = ip + str(ran)
cmd = Ip_range_scanner.command(self, new_ip)
threading.Thread(target=Ip_range_scanner.scan, args=[self,cmd, new_ip]).start()
while int(self.Activethreads) != 0:
''
print(self.table)
def Gethostname(self, ip):
try:
hostname = socket.gethostbyaddr(ip)[0]
return hostname
except:
return None
def Filter_info(self, user_input):
ip = user_input[1]
rang = user_input[2]
Ip_range_scanner.scanner(self,ip, rang)
def Checkbrowser(self, ip):
try:
requests.get(url=Scan_info.Prot + ip, timeout=5)
return True
except:
return False
def scan(self, cmd, ip):
self.Activethreads += 1
res = subprocess.Popen(cmd, shell=Scan_info.shell,stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
res.wait()
if res.returncode == 0:
browser = Ip_range_scanner.Checkbrowser(self, ip)
hostname = Ip_range_scanner.Gethostname(self, ip)
RDP = Ip_range_scanner.portscan(self, ip, Scan_info.RDP_port)
ssh = Ip_range_scanner.portscan(self, ip, Scan_info.SSH_port)
mac = Ip_range_scanner.Getmac(self, ip)
self.table.add_row([ip, hostname, browser, RDP, mac, ssh])
self.Activethreads -= 1