示例#1
0
 def test_max_count(self):
     """
     Testing max count flag.
     """
     for title, source in self.get_sources():
         self.assertEqual(2, grep(source, "h", c=True, m=2))
         self.assertEqual(2, grep(source, "h", c=True, m=2, i=True))
示例#2
0
 def test_whole_lines(self):
     """
     Testing whole lines flags.
     """
     for title, source in self.get_sources():
         self.assertListEqual(['hub'], grep(source, "hub", x=True))
         self.assertListEqual(['hub'], grep(source, "hub", x=True, F=True))
示例#3
0
 def test_count(self):
     """
     Testing count flag.
     """
     for title, source in self.get_sources():
         self.assertEqual(3, grep(source, "hub", c=True))
         self.assertEqual(4, grep(source, "h", c=True))
         self.assertEqual(6, grep(source, "h", c=True, i=True))
示例#4
0
 def test_keep_eol(self):
     """
     Testing keep eol flag.
     """
     self.assertListEqual(['chubby\n', 'hub\n', 'blue hub\n'],
                          grep(self.test_file, "hub", k=True))
     self.assertListEqual(['chubby', 'hub', 'blue hub'],
                          grep(self.test_list, "hub", k=True))
示例#5
0
 def test_whole_words(self):
     """
     Testing whole words flags.
     """
     for title, source in self.get_sources():
         self.assertListEqual(['hub', 'blue hub'],
                              grep(source, "hub", w=True))
         self.assertListEqual(['hub', 'blue hub'],
                              grep(source, "hub", w=True, F=True))
示例#6
0
 def test_quiet(self):
     """
     Testing quiet flag.
     """
     for title, source in self.get_sources():
         self.assertEqual(True, grep(source, "hub", c=True, q=True))
         self.assertEqual(True, grep(source, "hub", c=True, q=True, i=True))
         self.assertEqual(True, grep(source, "dog", c=True, q=True, i=True))
         self.assertEqual(False,
                          grep(source, "wrong", c=True, q=True, i=True))
示例#7
0
 def test_case_insensitive(self):
     """
     Testing case insensitive flags.
     """
     for title, source in self.get_sources():
         self.assertListEqual(
             ['chubby', 'hub', 'Hub', 'green HuB.', 'blue hub'],
             grep(source, "hub", i=True))
         self.assertListEqual(
             ['chubby', 'hub', 'Hub', 'green HuB.', 'blue hub'],
             grep(source, "hub", i=True, F=True))
示例#8
0
 def test_basic(self):
     """
     Testing basic grep with regex and fixed strings.
     """
     for title, source in self.get_sources():
         self.assertListEqual(['chubby', 'hub', 'blue hub'],
                              grep(source, "hub"))
         self.assertListEqual(['chubby', 'hub', 'blue hub'],
                              grep(source, "hub", F=True))
         self.assertListEqual(['chubby', 'hub', 'blue hub'],
                              grep(source, ["hub"], F=True))
         self.assertListEqual(['chubby', 'hub', 'dog', 'blue hub'],
                              grep(source, ["hub", "dog"], F=True))
示例#9
0
    def test_re_flags(self):
        """
        Testing re-flags flags.
        """
        import re
        for title, source in self.get_sources():

            # test re flag ignore case. note: in second call the flag is ignored because we use pattern as strings.
            self.assertListEqual(
                ['chubby', 'hub', 'Hub', 'green HuB.', 'blue hub'],
                grep(source, "hub", r=re.IGNORECASE))
            self.assertListEqual(['chubby', 'hub', 'blue hub'],
                                 grep(source, "hub", r=re.IGNORECASE, F=True))
示例#10
0
    def test_before_context(self):
        """
        Testing before context flag.
        """
        # test before-context alone
        for title, source in self.get_sources():
            self.assertListEqual([['hub', 'Hub', 'dog']],
                                 grep(source, "dog", B=2, t=True))
            self.assertListEqual([['chubby']],
                                 grep(source, "chubby", B=2, t=True))

        # combined with after-context
        for title, source in self.get_sources():
            self.assertListEqual([['hub', 'Hub', 'dog', 'hottub  ']],
                                 grep(source, "dog", B=2, A=1))
示例#11
0
    def test_after_context(self):
        """
        Testing after context flag.
        """
        # test after-context alone
        for title, source in self.get_sources():
            self.assertListEqual([['dog', 'hottub', 'green HuB.']],
                                 grep(source, "dog", A=2, t=True))
            self.assertListEqual([['blue hub']],
                                 grep(source, "blue hub", A=2, t=True))

        # combined with before-context
        for title, source in self.get_sources():
            self.assertListEqual([['Hub', 'dog', 'hottub', 'green HuB.']],
                                 grep(source, "dog", A=2, B=1, t=True))
示例#12
0
 def test_regex(self):
     """
     Testing a simple regex expression.
     """
     for title, source in self.get_sources():
         self.assertListEqual(['chubby', 'hub', 'blue hub'],
                              grep(source, "h.b"))
示例#13
0
 def test_line_number(self):
     """
     Testing line number flag.
     """
     for title, source in self.get_sources():
         self.assertListEqual([(0, 'chubby'), (1, 'hub'), (6, 'blue hub')],
                              grep(source, "hub", n=True))
示例#14
0
 def test_only_match(self):
     """
     Testing only_match flag.
     """
     for title, source in self.get_sources():
         self.assertListEqual(['hub', 'hub', 'Hub', 'HuB', 'hub'],
                              grep(source, "hub", o=True, i=True))
示例#15
0
 def test_offset(self):
     """
     Testing offset flag.
     """
     for title, source in self.get_sources():
         self.assertListEqual([(1, 'chubby'), (0, 'hub'), (5, 'blue hub')],
                              grep(source, "hub", b=True))
示例#16
0
    def test_invert(self):
        """
        Testing invert flags.
        """
        for title, source in self.get_sources():

            # check invert
            self.assertListEqual(['Hub', 'dog', 'hottub  ', 'green HuB.'],
                                 grep(source, "hub", v=True))
            self.assertListEqual(['Hub', 'dog', 'hottub  ', 'green HuB.'],
                                 grep(source, "hub", v=True, F=True))

            # check invert with case insensitive as well
            self.assertListEqual(['dog', 'hottub  '],
                                 grep(source, "hub", i=True, v=True))
            self.assertListEqual(['dog', 'hottub  '],
                                 grep(source, "hub", i=True, v=True, F=True))
示例#17
0
def port_scanner():
	global open_tcp, open_udp
	
	#create directories to store the scan results
	sp.call("mkdir {}".format(file_name), shell = True)
	sp.call("mkdir {}/XML".format(file_name), shell = True)
	sp.call("mkdir {}/nmap".format(file_name), shell = True)
	sp.call("mkdir {}/gnmap".format(file_name), shell = True)
	
	###############################################tcp scan#######################################
	
	if port_type == "tcp":
		#stage 1
		sp.call("nmap -T4 -sT -Pn -p- {} -oX {}/XML/tcp_scan1.xml -oN {}/nmap/tcp_scan1.nmap -oG {}/gnmap/tcp_scan1.gnmap".format(ip_addresse, file_name, file_name, file_name), shell = True)
	
		with open("{}/nmap/tcp_scan1.nmap".format(file_name), "r") as port_file:			
			for line in port_file:
				line = str(grep(line, "open")).split(" ")[0].translate(None, "/tcp")
				if line != "[]":
					line = line.translate(None, "['")
					open_tcp.append(line)
		
		open_tcp = ",".join(open_tcp)
	
		#stage 2
		sp.call("nmap -T4 -A -p{} {}".format(open_tcp, ip_addresse), shell = True)
	
	#############################################udp scan###########################################
	
	elif port_type == "udp":
		#stage 1
		sp.call("nmap -T4 -sU -p- {} -oX {}/XML/udp_scan1.xml -oN {}/nmap/udp_scan1.nmap -oG {}/gnmap/udp_scan1.gnmap".format(ip_addresse, file_name, file_name, file_name), shell = True)
		
		with open("{}/nmap/udp_scan1.nmap".format(file_name), "r") as port_file:			
			for line in port_file:
				line = str(grep(line, "open")).split(" ")[0].translate(None, "/udp")
				if line != "[]":
					line = line.translate(None, "['")
					open_udp.append(line)
		
		#stage 2
		sp.call("nmap -T4 -sU -A -p{} {}".format(open_tcp, ip_addresse), shell = True)
示例#18
0
def gethostname(shrun):
    hostname = grep(shrun, "host-name", "i=True")
    print("The hostname has been extracted.txt")
    print(hostname)
    return hostname
示例#19
0
 def test_trim(self):
     """
     Testing trim flag.
     """
     for title, source in self.get_sources():
         self.assertListEqual(['hottub'], grep(source, "hottub", t=True))