-
Notifications
You must be signed in to change notification settings - Fork 0
/
SwitchBox.py
executable file
·68 lines (54 loc) · 1.73 KB
/
SwitchBox.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
#!/usr/bin/python
from scapy.all import *
class SwitchBox():
def __init__(self, netIP, verb):
self.netIP = netIP #subnet IP
self.verb = verb
conf.verb = verb
self.sourceDict = {}
def scanNetwork(self, *args):
#print "Host and open ports (blank if nothing, might take awhile)"
for num in range(0, 256):
self.scanHost(self.netIP + str(num), *args)
#for port in args:
# layerIP = IP(dst = self.netIP + str(num))
# layerTCP = TCP(flags = 'S', dport = port)
# newPacket = layerIP/layerTCP
# reply = sr1(newPacket, timeout = 2)
# self.dictManage(reply)
#self.printCheck()
def scanHost(self, target, *args):
#print "Host and open ports (blank if nothing)"
for port in args:
layerIP = IP(dst = target)
layerTCP = TCP(dport = port, flags = 'S')
newPacket = layerIP/layerTCP
reply = sr1(newPacket, timeout = 1)
self.dictManage(reply)
self.printCheck()
def pingHost(self, target):
layerIP = IP(dst = target)
layerICMP = ICMP()/"Knock Knock"
newPacket = layerIP/layerICMP
reply = sr1(newPacket, timeout = 1)
if not (reply is None):
print reply.src + " is up"
def pingSweep(self):
for num in range(0, 256):
self.pingHost(self.netIP + str(num))
#layerIP = IP(dst = netIP + str(num))
#layerICMP = ICMP()/"Boo!"
#newPacket = layerIP/layerICMP
#reply = sr1(newPacket, timeout = 2)
#if not (reply is None):
# print reply.src + " is up"
#helper functions
def dictManage(self, reply):
if not (reply is None):
if not(reply.src in self.sourceDict):
self.sourceDict[reply.src] = []
self.sourceDict[reply.src].append(reply.sport)
def printCheck(self):
if (bool(self.sourceDict)):
print self.sourceDict
self.sourceDict = {}