Exemplo n.º 1
0
def minTree(inputArray, Tree=t.Node("root")):
    if len(inputArray) > 0:
        midpoint = len(inputArray) / 2
        midvalue = inputArray[midpoint]
        Tree.name = "Node"
        Tree.value = midvalue
        Tree.left = t.Node()
        Tree.right = t.Node()
        minTree(inputArray[0:midpoint], Tree.left)
        minTree(inputArray[(midpoint + 1):], Tree.right)
        return Tree
    return
Exemplo n.º 2
0
	def __init__(self,grid,tol,mode,partition):

		# The partitions are how we divide up the space and using a mixture of partitions
		# or a naturally varying partition gives us more robust edge detection

		acceptable_partitions= {'quad', 'shift_center', 'golden'}

		if partition not in acceptable_partitions:

			raise ValueError('Invalid Mode: please choose a valid mode {}'.format(acceptable_partitions.keys()))


		#determine how large the image is
		height, width, channels = grid.shape
		#Channels are equal to depth

		# starts with the whole image
		self.RootNode = treeNode.Node(None,0,0,height, width, grid, tol, 0, mode, partition)

		# save the image for later use
		self.Grid = grid

		self.Partition = partition

		self.Matrix = np.zeros((height,width))

		# add in the other three corners
		#self.Edges.append([width,  0])
		#self.Edges.append([width, -height])
		#self.Edges.append([0, -height])
		self.Cores		= []
		self.Edges		= [] #starts with the corners included

		self.Count = 0
Exemplo n.º 3
0
def testModel(model, filename):
    resetGlobalValues()
    sniffTestPackets(filename)
    entropyData = extractDNSQueryEntropy(entropyData, False)
    buildTree(root, False)
    subdomainCountData = calculateSubdomainCount(subdomainCountData, root,
                                                 False)
    qnamesLen = calculateQnamesLen(qnamesLen, False)
    testData = modifyData(entropyData, subdomainCountData, qnamesLen, False)
    preds = model.predict(testData)
    pktdump = scapy.utils.PcapWriter("results.pcap", append=True, sync=True)
    print("Analysis Completed.")
    print("Saving suspicious packets below to pcap file...(results.pcap)")
    resultsTree = treeNode.Node('', '')
    i = 0
    while i < len(preds):
        if preds[i] == -1:
            pktdump.write(testPackets[i])
            treeNode.populateTree(resultsTree, testPackets[i])
        i += 1
    print("Within the results, the breakdown of the domains are as such:")
    print("Ignoring any domains with only 1 subdomain...")
    resultsTree.printNodes()
Exemplo n.º 4
0
    current = root
    s = []
    done = 0
    print('\n')
    while not done:
        #print("here:")
        if current is not None:
            s.append(current)
            current = current.left
        else:
            if s:
                current = s.pop()
                print(current.val, end='')
                current = current.right
            else:
                done = 1


if __name__ == '__main__':
    ROOT = treeNode.Node(1)
    ROOT.left = treeNode.Node(2)
    ROOT.right = treeNode.Node(3)
    ROOT.left.left = treeNode.Node(4)
    ROOT.left.right = treeNode.Node(5)
    ROOT.right.left = treeNode.Node(6)
    ROOT.right.right = treeNode.Node(7)

    treeNode.printTree(ROOT)

    inorder(ROOT)
Exemplo n.º 5
0
def resetGlobalValues():
    root = treeNode.Node('', '')
    entropyData = []
    subdomainCountData = []
    qnamesLen = []