-
Notifications
You must be signed in to change notification settings - Fork 2
/
subnet.py
30 lines (27 loc) · 1.06 KB
/
subnet.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
from scapy.all import *
import host
class Subnet:
def __init__(self, netAddr, prefixLen, subnetMask, activeHosts):
self.netAddr = netAddr
self.prefixLen = prefixLen
self.subnetMask = subnetMask
if activeHosts is not None:
self.activeHosts = activeHosts
else:
self.activeHosts = []
def getActiveHosts(self):
print ("Scanning for active hosts on subnet " + self.netAddr + "/" + str(self.prefixLen))
suffixLen = 1 << (32 - self.prefixLen)
ipRange = self.netAddr + "/" + str(self.prefixLen)
activeHosts = []
for result in arping(ipRange, verbose = 1)[0].res:
ipAddr = result[0].pdst
activeHost = host.Host(ipAddr, self.prefixLen, self.subnetMask)
activeHosts.append(activeHost)
self.activeHosts = activeHosts
def fingerprintActiveHosts(self):
for host in self.activeHosts:
if not host.potentialOS:
host.getOSInfo()
if not host.actualOS:
host.nmapFingerprint()