diff --git a/Makefile.in b/Makefile.in index c1c7107..cc3ea8d 100644 --- a/Makefile.in +++ b/Makefile.in @@ -26,8 +26,8 @@ export LIBLINEAR_LIBS = @LIBLINEAR_LIBS@ export NCATDIR=@NCATDIR@ CC = @CC@ CXX = @CXX@ -CCOPT = -DBGFLAGS = +CCOPT = +DBGFLAGS = STRIP = @STRIP@ LIBPCAPDIR = @libpcapdir@ LIBPCREDIR = @LIBPCREDIR@ @@ -70,7 +70,7 @@ LINGUAS ?= $(ALL_LINGUAS) # DESTDIR is used by some package maintainers to install Nmap under -# its usual directory structure into a different tree. See the +# its usual directory structure into a different tree. See the # CHANGELOG for more info. DESTDIR = @@ -438,7 +438,7 @@ check-dns: tests/check_dns check: @NCAT_CHECK@ @NSOCK_CHECK@ @ZENMAP_CHECK@ @NSE_CHECK@ @NDIFF_CHECK@ check-dns -${srcdir}/configure: configure.ac +${srcdir}/configure: configure.ac cd ${srcdir} && autoconf ## autoheader might not change config.h.in, so touch a stamp file. diff --git a/ncat/scripts/p0fme.py b/ncat/scripts/p0fme.py index 5f4d42e..e890e46 100755 --- a/ncat/scripts/p0fme.py +++ b/ncat/scripts/p0fme.py @@ -2,6 +2,8 @@ from __future__ import print_function # logging, python2-only. +from builtins import map +from builtins import range """ A script that reads data generated by p0f -f p0f.log, looking for all entries about an IP read from NCAT_REMOTE_ADDR environment variable. Then it prints out @@ -80,7 +82,7 @@ if __name__ == "__main__": without_date = ''.join(without_date[1:]) # Create a key-value dictionary out of the '|'-separated substrings. - properties = dict(map(split_by_equals, without_date.split('|'))) + properties = dict(list(map(split_by_equals, without_date.split('|')))) if not properties['cli'].startswith(ip): continue # Not the IP we're looking for, check next one. diff --git a/ndiff/ndiff.py b/ndiff/ndiff.py index 043273f..580e7e4 100755 --- a/ndiff/ndiff.py +++ b/ndiff/ndiff.py @@ -13,6 +13,14 @@ # David Fifield # based on a design by Michael Pattrick +from __future__ import print_function +from past.builtins import cmp +from future import standard_library +standard_library.install_aliases() +from builtins import str +from builtins import range +from past.builtins import basestring +from builtins import object import datetime import difflib import getopt @@ -26,7 +34,7 @@ xml.__path__ = [x for x in xml.__path__ if "_xmlplus" not in x] import xml.sax import xml.sax.saxutils import xml.dom.minidom -from StringIO import StringIO +from io import StringIO verbose = False @@ -163,7 +171,7 @@ class Host(object): return state is None or state in self.extraports def extraports_string(self): - list = [(count, state) for (state, count) in self.extraports.items()] + list = [(count, state) for (state, count) in list(self.extraports.items())] # Reverse-sort by count. list.sort(reverse=True) return u", ".join( @@ -186,10 +194,10 @@ class Host(object): def extraports_to_dom_fragment(self, document): frag = document.createDocumentFragment() - for state, count in self.extraports.items(): + for state, count in list(self.extraports.items()): elem = document.createElement(u"extraports") elem.setAttribute(u"state", state) - elem.setAttribute(u"count", unicode(count)) + elem.setAttribute(u"count", str(count)) frag.appendChild(elem) return frag @@ -322,7 +330,7 @@ class Port(object): if self.state is None: return u"unknown" else: - return unicode(self.state) + return str(self.state) def spec_string(self): return u"%d/%s" % self.spec @@ -337,7 +345,7 @@ class Port(object): def to_dom_fragment(self, document): frag = document.createDocumentFragment() elem = document.createElement(u"port") - elem.setAttribute(u"portid", unicode(self.spec[0])) + elem.setAttribute(u"portid", str(self.spec[0])) elem.setAttribute(u"protocol", self.spec[1]) if self.state is not None: state_elem = document.createElement(u"state") @@ -474,14 +482,14 @@ def print_script_result_diffs_text(title, script_results_a, script_results_b, for sr_diff in script_result_diffs: sr_diff.append_to_port_table(table) if len(table) > 0: - print >> f + print(file=f) if len(script_results_b) == 0: - print >> f, u"-%s:" % title + print(u"-%s:" % title, file=f) elif len(script_results_a) == 0: - print >> f, u"+%s:" % title + print(u"+%s:" % title, file=f) else: - print >> f, u" %s:" % title - print >> f, table + print(u" %s:" % title, file=f) + print(table, file=f) def script_result_diffs_to_dom_fragment(elem, script_results_a, @@ -581,10 +589,10 @@ class ScanDiffText(ScanDiff): banner_a = format_banner(self.scan_a) banner_b = format_banner(self.scan_b) if banner_a != banner_b: - print >> self.f, u"-%s" % banner_a - print >> self.f, u"+%s" % banner_b + print(u"-%s" % banner_a, file=self.f) + print(u"+%s" % banner_b, file=self.f) elif verbose: - print >> self.f, u" %s" % banner_a + print(u" %s" % banner_a, file=self.f) def output_pre_scripts(self, pre_script_result_diffs): print_script_result_diffs_text("Pre-scan script results", @@ -597,7 +605,7 @@ class ScanDiffText(ScanDiff): post_script_result_diffs, self.f) def output_host_diff(self, h_diff): - print >> self.f + print(file=self.f) h_diff.print_text(self.f) def output_ending(self): @@ -719,9 +727,9 @@ class HostDiff(object): self.cost += os_cost extraports_a = tuple((count, state) - for (state, count) in self.host_a.extraports.items()) + for (state, count) in list(self.host_a.extraports.items())) extraports_b = tuple((count, state) - for (state, count) in self.host_b.extraports.items()) + for (state, count) in list(self.host_b.extraports.items())) if extraports_a != extraports_b: self.extraports_changed = True self.cost += 1 @@ -747,30 +755,30 @@ class HostDiff(object): # Names and addresses. if self.id_changed: if host_a.state is not None: - print >> f, u"-%s:" % host_a.format_name() + print(u"-%s:" % host_a.format_name(), file=f) if self.host_b.state is not None: - print >> f, u"+%s:" % host_b.format_name() + print(u"+%s:" % host_b.format_name(), file=f) else: - print >> f, u" %s:" % host_a.format_name() + print(u" %s:" % host_a.format_name(), file=f) # State. if self.state_changed: if host_a.state is not None: - print >> f, u"-Host is %s." % host_a.state + print(u"-Host is %s." % host_a.state, file=f) if host_b.state is not None: - print >> f, u"+Host is %s." % host_b.state + print(u"+Host is %s." % host_b.state, file=f) elif verbose: - print >> f, u" Host is %s." % host_b.state + print(u" Host is %s." % host_b.state, file=f) # Extraports. if self.extraports_changed: if len(host_a.extraports) > 0: - print >> f, u"-Not shown: %s" % host_a.extraports_string() + print(u"-Not shown: %s" % host_a.extraports_string(), file=f) if len(host_b.extraports) > 0: - print >> f, u"+Not shown: %s" % host_b.extraports_string() + print(u"+Not shown: %s" % host_b.extraports_string(), file=f) elif verbose: if len(host_a.extraports) > 0: - print >> f, u" Not shown: %s" % host_a.extraports_string() + print(u" Not shown: %s" % host_a.extraports_string(), file=f) # Port table. port_table = Table(u"** * * *") @@ -787,29 +795,29 @@ class HostDiff(object): port_diff.append_to_port_table(port_table, host_a, host_b) if len(port_table) > 1: - print >> f, port_table + print(port_table, file=f) # OS changes. if self.os_changed or verbose: if len(host_a.os) > 0: if len(host_b.os) > 0: - print >> f, u" OS details:" + print(u" OS details:", file=f) else: - print >> f, u"-OS details:" + print(u"-OS details:", file=f) elif len(host_b.os) > 0: - print >> f, u"+OS details:" + print(u"+OS details:", file=f) # os_diffs is a list of 5-tuples returned by # difflib.SequenceMatcher. for op, i1, i2, j1, j2 in self.os_diffs: if op == "replace" or op == "delete": for i in range(i1, i2): - print >> f, "- %s" % host_a.os[i] + print("- %s" % host_a.os[i], file=f) if op == "replace" or op == "insert": for i in range(j1, j2): - print >> f, "+ %s" % host_b.os[i] + print("+ %s" % host_b.os[i], file=f) if op == "equal": for i in range(i1, i2): - print >> f, " %s" % host_a.os[i] + print(" %s" % host_a.os[i], file=f) print_script_result_diffs_text("Host script results", host_a.script_results, host_b.script_results, @@ -1006,7 +1014,7 @@ class PortDiff(object): if (self.port_a.spec == self.port_b.spec and self.port_a.state == self.port_b.state): port_elem = document.createElement(u"port") - port_elem.setAttribute(u"portid", unicode(self.port_a.spec[0])) + port_elem.setAttribute(u"portid", str(self.port_a.spec[0])) port_elem.setAttribute(u"protocol", self.port_a.spec[1]) if self.port_a.state is not None: state_elem = document.createElement(u"state") @@ -1182,7 +1190,7 @@ class Table(object): def warn(str): """Print a warning to stderr.""" - print >> sys.stderr, str + print(str, file=sys.stderr) class NmapContentHandler(xml.sax.handler.ContentHandler): @@ -1441,7 +1449,7 @@ class XMLWriter (xml.sax.saxutils.XMLGenerator): def usage(): - print u"""\ + print(u"""\ Usage: %s [option] FILE1 FILE2 Compare two Nmap XML files and display a list of their differences. Differences include host state changes, port state changes, and changes to @@ -1451,7 +1459,7 @@ service and OS detection. -v, --verbose also show hosts and ports that haven't changed. --text display output in text format (default) --xml display output in XML format\ -""" % sys.argv[0] +""" % sys.argv[0]) EXIT_EQUAL = 0 EXIT_DIFFERENT = 1 @@ -1459,8 +1467,8 @@ EXIT_ERROR = 2 def usage_error(msg): - print >> sys.stderr, u"%s: %s" % (sys.argv[0], msg) - print >> sys.stderr, u"Try '%s -h' for help." % sys.argv[0] + print(u"%s: %s" % (sys.argv[0], msg), file=sys.stderr) + print(u"Try '%s -h' for help." % sys.argv[0], file=sys.stderr) sys.exit(EXIT_ERROR) @@ -1471,7 +1479,7 @@ def main(): try: opts, input_filenames = getopt.gnu_getopt( sys.argv[1:], "hv", ["help", "text", "verbose", "xml"]) - except getopt.GetoptError, e: + except getopt.GetoptError as e: usage_error(e.msg) for o, a in opts: if o == "-h" or o == "--help": @@ -1502,8 +1510,8 @@ def main(): scan_a.load_from_file(filename_a) scan_b = Scan() scan_b.load_from_file(filename_b) - except IOError, e: - print >> sys.stderr, u"Can't open file: %s" % str(e) + except IOError as e: + print(u"Can't open file: %s" % str(e), file=sys.stderr) sys.exit(EXIT_ERROR) if output_format == "text": diff --git a/ndiff/ndifftest.py b/ndiff/ndifftest.py index 2fa4ae0..e41ca29 100755 --- a/ndiff/ndifftest.py +++ b/ndiff/ndifftest.py @@ -2,6 +2,10 @@ # Unit tests for Ndiff. +from future import standard_library +standard_library.install_aliases() +from builtins import str +from past.builtins import basestring import subprocess import sys import unittest @@ -22,7 +26,7 @@ for x in dir(ndiff): sys.dont_write_bytecode = dont_write_bytecode del dont_write_bytecode -import StringIO +import io class scan_test(unittest.TestCase): @@ -52,7 +56,7 @@ class scan_test(unittest.TestCase): scan.load_from_file("test-scans/single.xml") host = scan.hosts[0] self.assertEqual(len(host.ports), 5) - self.assertEqual(host.extraports.items(), [("filtered", 95)]) + self.assertEqual(list(host.extraports.items()), [("filtered", 95)]) def test_extraports_multi(self): """Test that the correct number of known ports is returned when there @@ -197,8 +201,8 @@ class host_test(unittest.TestCase): h = s.hosts[0] self.assertEqual(len(h.ports), 5) self.assertEqual(len(h.extraports), 1) - self.assertEqual(h.extraports.keys()[0], u"filtered") - self.assertEqual(h.extraports.values()[0], 95) + self.assertEqual(list(h.extraports.keys())[0], u"filtered") + self.assertEqual(list(h.extraports.values())[0], 95) self.assertEqual(h.state, "up") @@ -703,7 +707,7 @@ class scan_diff_xml_test(unittest.TestCase): a.load_from_file("test-scans/empty.xml") b = Scan() b.load_from_file("test-scans/simple.xml") - f = StringIO.StringIO() + f = io.StringIO() self.scan_diff = ScanDiffXML(a, b, f) self.scan_diff.output() self.xml = f.getvalue() @@ -712,7 +716,7 @@ class scan_diff_xml_test(unittest.TestCase): def test_well_formed(self): try: document = xml.dom.minidom.parseString(self.xml) - except Exception, e: + except Exception as e: self.fail(u"Parsing XML diff output caused the exception: %s" % str(e)) @@ -739,8 +743,8 @@ def host_apply_diff(host, diff): host.os = diff.host_b.os[:] if diff.extraports_changed: - for state in host.extraports.keys(): - for port in host.ports.values(): + for state in list(host.extraports.keys()): + for port in list(host.ports.values()): if port.state == state: del host.ports[port.spec] host.extraports = diff.host_b.extraports.copy() diff --git a/ndiff/setup.py b/ndiff/setup.py index b5e254c..ff6277f 100644 --- a/ndiff/setup.py +++ b/ndiff/setup.py @@ -1,5 +1,8 @@ #!/usr/bin/env python +from __future__ import print_function +from builtins import str +from builtins import range import errno import sys import os @@ -94,7 +97,7 @@ class checked_install(distutils.command.install.install): self.saved_prefix = sys.prefix try: distutils.command.install.install.finalize_options(self) - except distutils.errors.DistutilsPlatformError, e: + except distutils.errors.DistutilsPlatformError as e: raise distutils.errors.DistutilsPlatformError(str(e) + """ Installing your distribution's python-dev package may solve this problem.""") @@ -227,7 +230,7 @@ for dir in dirs: uninstaller_file.close() # Set exec bit for uninstaller - mode = ((os.stat(uninstaller_filename)[ST_MODE]) | 0555) & 07777 + mode = ((os.stat(uninstaller_filename)[ST_MODE]) | 0o555) & 0o7777 os.chmod(uninstaller_filename, mode) def write_installed_files(self): @@ -242,7 +245,7 @@ for dir in dirs: try: for output in self.get_installed_files(): assert "\n" not in output - print >> f, output + print(output, file=f) finally: f.close() @@ -266,7 +269,7 @@ class my_uninstall(distutils.cmd.Command): # Read the list of installed files. try: f = open(INSTALLED_FILES_NAME, "r") - except IOError, e: + except IOError as e: if e.errno == errno.ENOENT: log.error("Couldn't open the installation record '%s'. " "Have you installed yet?" % INSTALLED_FILES_NAME) @@ -289,7 +292,7 @@ class my_uninstall(distutils.cmd.Command): try: if not self.dry_run: os.remove(file) - except OSError, e: + except OSError as e: log.error(str(e)) # Delete the directories. First reverse-sort the normalized paths by # length so that child directories are deleted before their parents. @@ -300,7 +303,7 @@ class my_uninstall(distutils.cmd.Command): log.info("Removing the directory '%s'." % dir) if not self.dry_run: os.rmdir(dir) - except OSError, e: + except OSError as e: if e.errno == errno.ENOTEMPTY: log.info("Directory '%s' not empty; not removing." % dir) else: diff --git a/ndiff/test-scans/anonymize.py b/ndiff/test-scans/anonymize.py index 9ba612a..46acc31 100755 --- a/ndiff/test-scans/anonymize.py +++ b/ndiff/test-scans/anonymize.py @@ -9,6 +9,9 @@ # expressions against things that look like address and host names. It is # possible that it will leave some identifying information. +from __future__ import print_function +from builtins import str +from builtins import range import hashlib import random import re @@ -33,7 +36,7 @@ def anonymize_mac_address(addr): def anonymize_ipv4_address(addr): r.seed(hash(addr)) nums = (10,) + tuple(r.randrange(256) for i in range(3)) - return u".".join(unicode(x) for x in nums) + return u".".join(str(x) for x in nums) def anonymize_ipv6_address(addr): @@ -58,7 +61,7 @@ def anonymize_hostname(name): num = r.randrange(1000) hostname_map[name] = u"%s-%d.example.com" % (prefix, num) if VERBOSE: - print >> sys.stderr, "Replace %s with %s" % (name, hostname_map[name]) + print("Replace %s with %s" % (name, hostname_map[name]), file=sys.stderr) return hostname_map[name] mac_re = re.compile(r'\b([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}\b') @@ -78,7 +81,7 @@ def anonymize_address(addr): else: assert False if VERBOSE: - print >> sys.stderr, "Replace %s with %s" % (addr, address_map[addr]) + print("Replace %s with %s" % (addr, address_map[addr]), file=sys.stderr) return address_map[addr] diff --git a/nping/nping-dev/ipv6fp.py b/nping/nping-dev/ipv6fp.py index b21dbdd..280c05e 100755 --- a/nping/nping-dev/ipv6fp.py +++ b/nping/nping-dev/ipv6fp.py @@ -8,6 +8,13 @@ # {luis.mgarc@gmail.com} # # # ################################################################################ +from __future__ import division +from __future__ import print_function +from builtins import hex +from builtins import input +from builtins import str +from builtins import range +from past.utils import old_div import getopt import sys from scapy.all import * @@ -225,19 +232,19 @@ def get_icmp_seq_number(): ############################# def print_start_separator(): - print "---------------------------------- BEGIN TEST ----------------------------------" + print("---------------------------------- BEGIN TEST ----------------------------------") def print_end_separator(): - print "---------------------------------- END OF TEST ---------------------------------" + print("---------------------------------- END OF TEST ---------------------------------") def print_sent_packet(test_packet): if type(test_packet)==list : for i in range(0, len(test_packet)) : - print "[+] Test Packet #" + str(i) + ":" + print("[+] Test Packet #" + str(i) + ":") test_packet[i].show2() hexdump(test_packet[i]) else : - print "[+] Test Packet:" + print("[+] Test Packet:") test_packet.show2() hexdump(test_packet) @@ -245,7 +252,7 @@ def store_line(line2print): output_data.append("#PARSE# "+line2print) def print_and_store_line(line2print): - print "[#] " + line2print + print("[#] " + line2print) store_line(line2print) def print_received_packet(packet): @@ -291,7 +298,7 @@ def print_parseable_test_result(test_number, responses, ip_version): break except : response[layers-i-2].remove_payload() - print "Error displaying packet. Removing layer "+str(layers-i) + print("Error displaying packet. Removing layer "+str(layers-i)) removed=removed+1 # Print result status (Truncated, Full or Empty) along with the total number of layers and the number of layers that were chopped. @@ -339,85 +346,85 @@ def print_test_number(test_num): print_and_store_line("test_no=" + str(test_num)) def print_test_description(test_desc): - print "[+] Test Description: " + str(test_desc) + print("[+] Test Description: " + str(test_desc)) def print_welcome_banner(): - print "=================================================================" - print "== NMAP IPv6 OS DETECTION RESEARCH TOOL ==" - print "=================================================================" - print " You are running ipv6fp, an internal research tool for the Nmap " - print " Security Scanner. This program will send about 150 IPv6 network " - print " probes to a target system and collect any responses received. " - print " The results will let us build a new IPv6 stack fingerprinting " - print " engine in Nmap. " - print " " - print " We'd like to thank you in advance for running this tool. After " - print " the execution has finished, a file with the following name " - print " will be created in the working directory: " - print " " - print output_file_name_g.center(65) - print " " - print " Please send it to the following address: " + result_report_email_g - print " " - print "=================================================================" + print("=================================================================") + print("== NMAP IPv6 OS DETECTION RESEARCH TOOL ==") + print("=================================================================") + print(" You are running ipv6fp, an internal research tool for the Nmap ") + print(" Security Scanner. This program will send about 150 IPv6 network ") + print(" probes to a target system and collect any responses received. ") + print(" The results will let us build a new IPv6 stack fingerprinting ") + print(" engine in Nmap. ") + print(" ") + print(" We'd like to thank you in advance for running this tool. After ") + print(" the execution has finished, a file with the following name ") + print(" will be created in the working directory: ") + print(" ") + print(output_file_name_g.center(65)) + print(" ") + print(" Please send it to the following address: " + result_report_email_g) + print(" ") + print("=================================================================") def print_debug_info(): - print "== IPv6 Routing information =====================================" - print conf.route6 - print "== IPv4 Routing information =====================================" - print conf.route - print "== Other Details ================================================" - print "[+] IPv4 Interface: " + conf.iface - print "[+] IPv6 Interface: " + conf.iface6 - print "[+] User interface: " + interface_g - print "[+] IPv6 enabled: " + str(conf.ipv6_enabled) - print "[+] Python version: " + sys.version.replace('\n', '') - print "[+] Scapy version: " + conf.version - print "[+] Run as root: " + str(os.geteuid()==0) + print("== IPv6 Routing information =====================================") + print(conf.route6) + print("== IPv4 Routing information =====================================") + print(conf.route) + print("== Other Details ================================================") + print("[+] IPv4 Interface: " + conf.iface) + print("[+] IPv6 Interface: " + conf.iface6) + print("[+] User interface: " + interface_g) + print("[+] IPv6 enabled: " + str(conf.ipv6_enabled)) + print("[+] Python version: " + sys.version.replace('\n', '')) + print("[+] Scapy version: " + conf.version) + print("[+] Run as root: " + str(os.geteuid()==0)) if target_os_details_g!=None: - print "[+] OS Type: " + target_os_details_g[0] - print "[+] OS Sub-type: " + target_os_details_g[1] - print "[+] OS Version: " + target_os_details_g[2] + print("[+] OS Type: " + target_os_details_g[0]) + print("[+] OS Sub-type: " + target_os_details_g[1]) + print("[+] OS Version: " + target_os_details_g[2]) if target_host6_g!=None : - print "[+] Dst IPv6 Address: " + str(target_host6_g) + print("[+] Dst IPv6 Address: " + str(target_host6_g)) if target_host4_g!=None : - print "[+] Dst IPv4 Address: " + str(target_host4_g) + print("[+] Dst IPv4 Address: " + str(target_host4_g)) if source_ipv6_addr_g!=None : - print "[+] Src IPv6 Address: " + str(source_ipv6_addr_g) + print("[+] Src IPv6 Address: " + str(source_ipv6_addr_g)) if source_ipv4_addr_g!=None : - print "[+] Src IPv4 Address: " + str(source_ipv4_addr_g) + print("[+] Src IPv4 Address: " + str(source_ipv4_addr_g)) if target_mac_addr_g!=None: - print "[+] Gateway MAC: " + str(target_mac_addr_g) - - print "[+] Send eth: " + str(send_eth_g) - print "[+] Open Port: " + str(open_port_g) - print "[+] Open Port: " + str(closed_port_g) - print "[+] Timeout: " + str(capture_timeout_g) - print "[+] Retries: " + str(packet_retries_g) - print "[+] Inter-test delay: " + str(inter_test_delay_g) - print "[+] Inter-packet delay: " + str(inter_packet_delay_g) - print "[+] Debug: " + str(debug_g) - print "=================================================================" + print("[+] Gateway MAC: " + str(target_mac_addr_g)) + + print("[+] Send eth: " + str(send_eth_g)) + print("[+] Open Port: " + str(open_port_g)) + print("[+] Open Port: " + str(closed_port_g)) + print("[+] Timeout: " + str(capture_timeout_g)) + print("[+] Retries: " + str(packet_retries_g)) + print("[+] Inter-test delay: " + str(inter_test_delay_g)) + print("[+] Inter-packet delay: " + str(inter_packet_delay_g)) + print("[+] Debug: " + str(debug_g)) + print("=================================================================") def print_test_results(): - print "=================================================================" - print "== NMAP IPv6 OS DETECTION TEST RESULTS ==" - print "=================================================================" + print("=================================================================") + print("== NMAP IPv6 OS DETECTION TEST RESULTS ==") + print("=================================================================") if target_host4_g!=None : for i in range(0, len(test4_replies)) : sys.stdout.write("IPv4 TEST #") sys.stdout.write(str(test4_ids[i])) sys.stdout.write("=") if test4_replies[i]!=None : - print "Response received" + print("Response received") else : - print "No response" + print("No response") if target_host6_g!=None : j=0 for i in range(first_test_g, min( len(test6_replies), last_test_g+1) ) : @@ -425,13 +432,13 @@ def print_test_results(): sys.stdout.write(str(test6_ids[i])) sys.stdout.write("=") if test6_replies[j]!=None : - print "Response received" + print("Response received") else : - print "No response" + print("No response") j=j+1 - print "=================================================================" - print "== SUMMARY OF RESULTS ==" - print "=================================================================" + print("=================================================================") + print("== SUMMARY OF RESULTS ==") + print("=================================================================") print_and_store_line("currtime={" + str(time.time()) +", " + time.ctime()+"}" ) if target_os_details_g!=None: print_and_store_line("ostype="+target_os_details_g[0]) @@ -450,24 +457,24 @@ def print_test_results(): print_and_store_line("rvector6=" + str(result_vector6)) if len(result_vector4) > 0 : print_and_store_line("rvector4=" + str(result_vector4)) - print " " - print " Thank you for running this tool. A file with the following name " - print " has been created in the working directory: " - print " " - print output_file_name_g.center(65) - print " " + print(" ") + print(" Thank you for running this tool. A file with the following name ") + print(" has been created in the working directory: ") + print(" ") + print(output_file_name_g.center(65)) + print(" ") if target_os_details_g!=None: - print " Please send it to the following address: " + result_report_email_g + print(" Please send it to the following address: " + result_report_email_g) else : - print " Please edit the file to provide details about the target's " - print " operating system type and version. Read the instructions at the " - print " top. " - print " " - print " Once you're done, please send the file to the following address:" - print " " - print result_report_email_g.center(65) - print " " - print "=================================================================" + print(" Please edit the file to provide details about the target's ") + print(" operating system type and version. Read the instructions at the ") + print(" top. ") + print(" ") + print(" Once you're done, please send the file to the following address:") + print(" ") + print(result_report_email_g.center(65)) + print(" ") + print("=================================================================") def get_results_file_header(): text= [ '================================================================================', @@ -528,7 +535,7 @@ def print_time_elapsed(): print_and_store_line("elapsed=" + str(get_time_elapsed())) def print_usage(f = sys.stdout): - print >> f, """\ + print("""\ Usage: %(progname)s {Target} [Options] OPTIONS: @@ -548,11 +555,11 @@ Usage: %(progname)s {Target} [Options] --addr4=ADDR Specify the target's IPv4 address. --interactive Ask parameter values interactively. """ % { "progname": sys.argv[0], "ot": DEFAULT_OPEN_PORT_IN_TARGET, - "ct": DEFAULT_CLOSED_PORT_IN_TARGET } + "ct": DEFAULT_CLOSED_PORT_IN_TARGET }, file=f) def print_debug(debug_msg): if( debug_g==True and debug_msg!=None): - print debug_msg + print(debug_msg) ######################## @@ -967,7 +974,7 @@ def sndrcv_ng(pkt, timeout=1, iface=None, inter = 0, verbose=1, retry=0, multi=0 send(pkt, inter=inter, verbose=verbose) elif pid < 0: - print "ERROR: unable to fork()" + print("ERROR: unable to fork()") # Packet reception child else: @@ -1024,9 +1031,9 @@ def send_and_receive_eth(packet, verbosity=1): eth_hdr=Ether(dst=target_mac_addr_g) if type(packet)==list : # Test contains more than one packet for i in range(0, len(packet)) : - packet[i]=eth_hdr/packet[i] + packet[i]=old_div(eth_hdr,packet[i]) else : - packet=eth_hdr/packet + packet=old_div(eth_hdr,packet) responses=send_and_receive(packet, verbosity=verbosity) @@ -1040,9 +1047,9 @@ def send_and_receive_eth_multiple(packet, verbosity=1): eth_hdr=Ether(dst=target_mac_addr_g) if type(packet)==list : # Test contains more than one packet for i in range(0, len(packet)) : - packet[i]=eth_hdr/packet[i] + packet[i]=old_div(eth_hdr,packet[i]) else : - packet=eth_hdr/packet + packet=old_div(eth_hdr,packet) responses=srp(packet, iface=interface_g, retry=packet_retries_g, timeout=capture_timeout_g, multi=1, verbose=verbosity, inter=inter_packet_delay_g); return responses @@ -1081,13 +1088,13 @@ def run_test(test_number, test_id, test_description, test_packet, ip_version): # Check if we got a response. Print it if that's the case. received=[] if(len(responses)>0 ): - print "[+] Response received:" + print("[+] Response received:") for i in range(0, len(responses)) : print_received_packet(responses[i][1]) received.append(responses[i][1]) else : received=None - print "[+] No response received:" + print("[+] No response received:") print_parseable_test_result(test_number, received, ip_version) @@ -1123,7 +1130,7 @@ def run_test_multiple(test_number_base, test_id, test_description, test_packet, # Print packets that did not get any response for i in range(0, len(responses[1])) : print_sent_packet(responses[1][i]) - print "[+] No response received:" + print("[+] No response received:") # Print packets that did get responses for i in range(0, len(responses[0])) : @@ -1131,7 +1138,7 @@ def run_test_multiple(test_number_base, test_id, test_description, test_packet, print_sent_packet(responses[0][i][0].payload) else : print_sent_packet(responses[0][i][0]) - print "[+] Response received:" + print("[+] Response received:") if type(responses[0][i][1])==scapy.layers.l2.Ether : print_received_packet(responses[0][i][1].payload) @@ -1177,9 +1184,9 @@ def set_up_ipv6_tests(target): tcp_packet.seq=tcpSeqBase+0 tcp_packet.ack=tcpAck tcp_packet.flags='S' - tcp_packet.options=[('WScale', 10), ('NOP', None), ('MSS',1460), ('Timestamp', (0xFFFFFFFF,0L)), ('SAckOK', '')] + tcp_packet.options=[('WScale', 10), ('NOP', None), ('MSS',1460), ('Timestamp', (0xFFFFFFFF,0)), ('SAckOK', '')] tcp_packet.window=1 - final_packet=ip_packet/tcp_packet + final_packet=old_div(ip_packet,tcp_packet) test6_packets.append(final_packet) # TEST 1 @@ -1192,9 +1199,9 @@ def set_up_ipv6_tests(target): tcp_packet.seq=tcpSeqBase+1 tcp_packet.ack=tcpAck tcp_packet.flags='S' - tcp_packet.options=[('MSS', 1400), ('WScale', 0), ('SAckOK', ''), ('Timestamp', (0xFFFFFFFF,0L)), ('EOL', '')] + tcp_packet.options=[('MSS', 1400), ('WScale', 0), ('SAckOK', ''), ('Timestamp', (0xFFFFFFFF,0)), ('EOL', '')] tcp_packet.window=63 - final_packet=ip_packet/tcp_packet + final_packet=old_div(ip_packet,tcp_packet) test6_packets.append(final_packet) # TEST 2 @@ -1207,9 +1214,9 @@ def set_up_ipv6_tests(target): tcp_packet.seq=tcpSeqBase+2 tcp_packet.ack=tcpAck tcp_packet.flags='S' - tcp_packet.options=[('Timestamp', (0xFFFFFFFF,0L)), ('NOP', ''), ('NOP', ''), ('WScale', 5), ('NOP', ''), ('MSS', 640)] + tcp_packet.options=[('Timestamp', (0xFFFFFFFF,0)), ('NOP', ''), ('NOP', ''), ('WScale', 5), ('NOP', ''), ('MSS', 640)] tcp_packet.window=4 - final_packet=ip_packet/tcp_packet + final_packet=old_div(ip_packet,tcp_packet) test6_packets.append(final_packet) # TEST 3 @@ -1222,9 +1229,9 @@ def set_up_ipv6_tests(target): tcp_packet.seq=tcpSeqBase+3 tcp_packet.ack=tcpAck tcp_packet.flags='S' - tcp_packet.options=[('SAckOK', ''), ('Timestamp', (0xFFFFFFFF,0L)), ('WScale', 10), ('EOL', '')] + tcp_packet.options=[('SAckOK', ''), ('Timestamp', (0xFFFFFFFF,0)), ('WScale', 10), ('EOL', '')] tcp_packet.window=4 - final_packet=ip_packet/tcp_packet + final_packet=old_div(ip_packet,tcp_packet) test6_packets.append(final_packet) # TEST 4 @@ -1237,9 +1244,9 @@ def set_up_ipv6_tests(target): tcp_packet.seq=tcpSeqBase+4 tcp_packet.ack=tcpAck tcp_packet.flags='S' - tcp_packet.options=[('MSS', 536), ('SAckOK', ''), ('Timestamp', (0xFFFFFFFF,0L)), ('WScale', 10), ('EOL', '')] + tcp_packet.options=[('MSS', 536), ('SAckOK', ''), ('Timestamp', (0xFFFFFFFF,0)), ('WScale', 10), ('EOL', '')] tcp_packet.window=16 - final_packet=ip_packet/tcp_packet + final_packet=old_div(ip_packet,tcp_packet) test6_packets.append(final_packet) # TEST 5 @@ -1252,9 +1259,9 @@ def set_up_ipv6_tests(target): tcp_packet.seq=tcpSeqBase+5 tcp_packet.ack=tcpAck tcp_packet.flags='S' - tcp_packet.options=[('MSS', 265), ('SAckOK', ''), ('Timestamp', (0xFFFFFFFF,0L))] + tcp_packet.options=[('MSS', 265), ('SAckOK', ''), ('Timestamp', (0xFFFFFFFF,0))] tcp_packet.window=512 - final_packet=ip_packet/tcp_packet + final_packet=old_div(ip_packet,tcp_packet) test6_packets.append(final_packet) # TEST 6 ECN @@ -1270,7 +1277,7 @@ def set_up_ipv6_tests(target): tcp_packet.flags='CES' tcp_packet.options=[('WScale', 10), ('NOP', ''), ('MSS', 1460), ('SAckOK', ''), ('NOP', ''), ('NOP', '')] tcp_packet.window=3 - final_packet=ip_packet/tcp_packet + final_packet=old_div(ip_packet,tcp_packet) test6_packets.append(final_packet) # TEST 7 (T2) @@ -1284,9 +1291,9 @@ def set_up_ipv6_tests(target): tcp_packet.ack=tcpAck tcp_packet.urgptr=0 tcp_packet.flags='' - tcp_packet.options=[('WScale', 10), ('NOP', ''), ('MSS', 265), ('Timestamp', (0xFFFFFFFF,0L)), ('SAckOK', '')] + tcp_packet.options=[('WScale', 10), ('NOP', ''), ('MSS', 265), ('Timestamp', (0xFFFFFFFF,0)), ('SAckOK', '')] tcp_packet.window=128 - final_packet=ip_packet/tcp_packet + final_packet=old_div(ip_packet,tcp_packet) test6_packets.append(final_packet) # TEST 8 (T3) @@ -1300,9 +1307,9 @@ def set_up_ipv6_tests(target): tcp_packet.ack=tcpAck tcp_packet.urgptr=0 tcp_packet.flags='SFUP' - tcp_packet.options=[('WScale', 10), ('NOP', ''), ('MSS', 265), ('Timestamp', (0xFFFFFFFF,0L)), ('SAckOK', '')] + tcp_packet.options=[('WScale', 10), ('NOP', ''), ('MSS', 265), ('Timestamp', (0xFFFFFFFF,0)), ('SAckOK', '')] tcp_packet.window=256 - final_packet=ip_packet/tcp_packet + final_packet=old_div(ip_packet,tcp_packet) test6_packets.append(final_packet) # TEST 9 (T4) @@ -1316,9 +1323,9 @@ def set_up_ipv6_tests(target): tcp_packet.ack=tcpAck tcp_packet.urgptr=0 tcp_packet.flags='A' - tcp_packet.options=[('WScale', 10), ('NOP', ''), ('MSS', 265), ('Timestamp', (0xFFFFFFFF,0L)), ('SAckOK', '')] + tcp_packet.options=[('WScale', 10), ('NOP', ''), ('MSS', 265), ('Timestamp', (0xFFFFFFFF,0)), ('SAckOK', '')] tcp_packet.window=1024 - final_packet=ip_packet/tcp_packet + final_packet=old_div(ip_packet,tcp_packet) test6_packets.append(final_packet) # TEST 10 (T5) @@ -1332,9 +1339,9 @@ def set_up_ipv6_tests(target): tcp_packet.ack=tcpAck tcp_packet.urgptr=0 tcp_packet.flags='S' - tcp_packet.options=[('WScale', 10), ('NOP', ''), ('MSS', 265), ('Timestamp', (0xFFFFFFFF,0L)), ('SAckOK', '')] + tcp_packet.options=[('WScale', 10), ('NOP', ''), ('MSS', 265), ('Timestamp', (0xFFFFFFFF,0)), ('SAckOK', '')] tcp_packet.window=31337 - final_packet=ip_packet/tcp_packet + final_packet=old_div(ip_packet,tcp_packet) test6_packets.append(final_packet) # TEST 11 (T6) @@ -1348,9 +1355,9 @@ def set_up_ipv6_tests(target): tcp_packet.ack=tcpAck tcp_packet.urgptr=0 tcp_packet.flags='A' - tcp_packet.options=[('WScale', 10), ('NOP', ''), ('MSS', 265), ('Timestamp', (0xFFFFFFFF,0L)), ('SAckOK', '')] + tcp_packet.options=[('WScale', 10), ('NOP', ''), ('MSS', 265), ('Timestamp', (0xFFFFFFFF,0)), ('SAckOK', '')] tcp_packet.window=32768 - final_packet=ip_packet/tcp_packet + final_packet=old_div(ip_packet,tcp_packet) test6_packets.append(final_packet) # TEST 12 (T7) @@ -1364,9 +1371,9 @@ def set_up_ipv6_tests(target): tcp_packet.ack=tcpAck tcp_packet.urgptr=0 tcp_packet.flags='FPU' - tcp_packet.options=[('WScale', 15), ('NOP', ''), ('MSS', 265), ('Timestamp', (0xFFFFFFFF,0L)), ('SAckOK', '')] + tcp_packet.options=[('WScale', 15), ('NOP', ''), ('MSS', 265), ('Timestamp', (0xFFFFFFFF,0)), ('SAckOK', '')] tcp_packet.window=65535 - final_packet=ip_packet/tcp_packet + final_packet=old_div(ip_packet,tcp_packet) test6_packets.append(final_packet) # TEST 13 (IE 1) @@ -1379,7 +1386,7 @@ def set_up_ipv6_tests(target): icmp_packet.seq=295 icmp_packet.id=0xABCD icmp_packet.data='\x00'*120 - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 14 (IE 2) @@ -1392,7 +1399,7 @@ def set_up_ipv6_tests(target): icmp_packet.seq=295+1 icmp_packet.id=0xABCD+1 icmp_packet.data='\x00'*150 - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 15 (U1) @@ -1416,7 +1423,7 @@ def set_up_ipv6_tests(target): ip_packet=build_default_ipv6(target) icmp_packet=build_default_icmpv6() icmp_packet.seq=get_icmp_seq_number() - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 17 @@ -1426,7 +1433,7 @@ def set_up_ipv6_tests(target): icmp_packet=build_default_icmpv6() icmp_packet.seq=get_icmp_seq_number() icmp_packet.data=ASCII_PAYLOAD_32 - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 18 @@ -1436,7 +1443,7 @@ def set_up_ipv6_tests(target): icmp_packet=build_default_icmpv6() icmp_packet.seq=get_icmp_seq_number() icmp_packet.data="A"*1232 - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 19 @@ -1446,7 +1453,7 @@ def set_up_ipv6_tests(target): icmp_packet=build_default_icmpv6() icmp_packet.seq=get_icmp_seq_number() icmp_packet.data="B"*1233 - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 20 @@ -1457,7 +1464,7 @@ def set_up_ipv6_tests(target): icmp_packet.seq=get_icmp_seq_number() icmp_packet.data=ASCII_PAYLOAD_32 icmp_packet.cksum=0xABCD - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 21 @@ -1468,7 +1475,7 @@ def set_up_ipv6_tests(target): icmp_packet=ICMPv6ND_NS() icmp_packet.code=0 icmp_packet.tgt=target; - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 22 @@ -1479,7 +1486,7 @@ def set_up_ipv6_tests(target): icmp_packet=ICMPv6ND_NS() icmp_packet.code=0x01 icmp_packet.tgt=target; - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 23 @@ -1490,7 +1497,7 @@ def set_up_ipv6_tests(target): icmp_packet=ICMPv6ND_NS() icmp_packet.code=0xAB icmp_packet.tgt=target; - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 24 @@ -1501,7 +1508,7 @@ def set_up_ipv6_tests(target): icmp_packet=ICMPv6ND_NS() icmp_packet.code=0 icmp_packet.tgt="::0" - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 25 @@ -1512,7 +1519,7 @@ def set_up_ipv6_tests(target): icmp_packet=ICMPv6ND_NS() icmp_packet.code=0xCD icmp_packet.tgt="::0" - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 26 @@ -1579,7 +1586,7 @@ def set_up_ipv6_tests(target): icmp_option_1.lladdr='1A:2B:3C:4D:5E:6F' icmp_option_2=ICMPv6NDOptMTU() icmp_option_2.mtu=1450 - icmp_options=icmp_option_1/icmp_option_2 + icmp_options=old_div(icmp_option_1,icmp_option_2) final_packet=ip_packet/icmp_packet/icmp_options test6_packets.append(final_packet) @@ -1591,7 +1598,7 @@ def set_up_ipv6_tests(target): icmp_packet.code=0 icmp_packet.id=0 icmp_packet.res=0 - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 32 @@ -1602,7 +1609,7 @@ def set_up_ipv6_tests(target): icmp_packet.code=0xFA icmp_packet.id=0 icmp_packet.res=0 - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 33 @@ -1613,7 +1620,7 @@ def set_up_ipv6_tests(target): icmp_packet.code=0 icmp_packet.id=0xABCD icmp_packet.res=0x1234 - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 34 @@ -1624,7 +1631,7 @@ def set_up_ipv6_tests(target): icmp_packet=ICMPv6ND_RS() icmp_packet.code=0 icmp_packet.res=0 - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 35 @@ -1635,7 +1642,7 @@ def set_up_ipv6_tests(target): icmp_packet=ICMPv6ND_RS() icmp_packet.code=0xAA icmp_packet.res=0 - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 36 @@ -1646,7 +1653,7 @@ def set_up_ipv6_tests(target): icmp_packet=ICMPv6ND_RS() icmp_packet.code=0 icmp_packet.res=0xAB0000CD - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 37 @@ -1657,7 +1664,7 @@ def set_up_ipv6_tests(target): icmp_packet=ICMPv6ND_RS() icmp_packet.code=0x01 icmp_packet.res=0x00000001 - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 38 @@ -1723,7 +1730,7 @@ def set_up_ipv6_tests(target): icmp_packet.nonce='\x01\x02\x03\x04\x05\x06\x07\x08' icmp_packet.unused=0 icmp_packet.data='\x00' - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 43 @@ -1737,7 +1744,7 @@ def set_up_ipv6_tests(target): icmp_packet.nonce='x02\x03\x04\x05\x06\x07\x08\x09' icmp_packet.unused=0 icmp_packet.data="\x09localhost\x00" - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 44 @@ -1751,7 +1758,7 @@ def set_up_ipv6_tests(target): icmp_packet.nonce='\x03\x04\x05\x06\x07\x08\x09\x0A' icmp_packet.unused=0 icmp_packet.data="\x40"+"0123456789012345678901234567890123456789012345678901234567890123"+"\x00" - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 45 @@ -1765,7 +1772,7 @@ def set_up_ipv6_tests(target): icmp_packet.nonce='\x04\x05\x06\x07\x08\x09\x0A\x0B' icmp_packet.unused=0 icmp_packet.data="\x3F"+"01234567890"+"\x00" # Wireshark reports "Malformed ICMPv6" - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 46 @@ -1779,7 +1786,7 @@ def set_up_ipv6_tests(target): icmp_packet.nonce='\x05\x06\x07\x08\x09\x0A\x0B\x0C' icmp_packet.unused=0 icmp_packet.data='\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 47 @@ -1793,7 +1800,7 @@ def set_up_ipv6_tests(target): icmp_packet.nonce='\x06\x07\x08\x09\x0A\x0B\x0C\x0D' icmp_packet.unused=0 icmp_packet.data=target - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 48 @@ -1807,7 +1814,7 @@ def set_up_ipv6_tests(target): icmp_packet.nonce='\x07\x08\x09\x0A\x0B\x0C\x0D\x0E' icmp_packet.unused=0 icmp_packet.data='\x00' - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 49 @@ -1821,7 +1828,7 @@ def set_up_ipv6_tests(target): icmp_packet.nonce='\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F' icmp_packet.unused=0 icmp_packet.data="\x09localhost\x00" - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 50 @@ -1835,7 +1842,7 @@ def set_up_ipv6_tests(target): icmp_packet.nonce='\x09\x0A\x0B\x0C\x0D\x0E\x0F\x00' icmp_packet.unused=0 icmp_packet.data=target - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 51 @@ -1849,7 +1856,7 @@ def set_up_ipv6_tests(target): icmp_packet.nonce='\x0A\x0B\x0C\x0D\x0E\x0F\x00\x01' icmp_packet.unused=0 icmp_packet.data="\x09localhost\x00" - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 52 @@ -1863,7 +1870,7 @@ def set_up_ipv6_tests(target): icmp_packet.nonce='\x0C\x0D\x0E\x0F\x00\x01\x02\x03' icmp_packet.unused=0 icmp_packet.data=target - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 53 @@ -1877,7 +1884,7 @@ def set_up_ipv6_tests(target): icmp_packet.nonce='\x0D\x0E\x0F\x00\x01\x02\x03\x04' icmp_packet.unused=0 icmp_packet.data=target - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 54 @@ -1891,7 +1898,7 @@ def set_up_ipv6_tests(target): icmp_packet.nonce='\x0E\x0F\x00\x01\x02\x03\x04\x05' icmp_packet.unused=0 icmp_packet.data=target - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 55 @@ -1905,7 +1912,7 @@ def set_up_ipv6_tests(target): icmp_packet.nonce='\x0F\x00\x01\x02\x03\x04\x05\x06' icmp_packet.unused=0 icmp_packet.data="\x09localhost\x00" - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 56 @@ -1919,7 +1926,7 @@ def set_up_ipv6_tests(target): icmp_packet.nonce='\x00\x01\x02\x03\x04\x05\x06\x07' icmp_packet.unused=0 icmp_packet.data="\x09localhost\x00" - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 57 @@ -1933,7 +1940,7 @@ def set_up_ipv6_tests(target): icmp_packet.nonce='\x01\x02\x03\x04\x05\x06\x07\x0A' icmp_packet.unused=0 icmp_packet.data=target - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 58 @@ -1947,7 +1954,7 @@ def set_up_ipv6_tests(target): icmp_packet.nonce='\x01\x02\x03\x04\x05\x06\x07\x0B' icmp_packet.unused=0 icmp_packet.data=target - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 59 @@ -1961,7 +1968,7 @@ def set_up_ipv6_tests(target): icmp_packet.nonce='\x01\x02\x03\x04\x05\x06\x07\x0C' icmp_packet.unused=0 icmp_packet.data=target - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) ################################ @@ -1986,7 +1993,7 @@ def set_up_ipv6_tests(target): ip_packet=build_default_ipv6(target) ext_hdr=IPv6ExtHdrDestOpt() ext_hdr.nh=59 # No Next Header - final_packet=ip_packet/ext_hdr + final_packet=old_div(ip_packet,ext_hdr) test6_packets.append(final_packet) # TEST 62 @@ -1995,7 +2002,7 @@ def set_up_ipv6_tests(target): ip_packet=build_default_ipv6(target) ext_hdr=IPv6ExtHdrDestOpt() ext_hdr.nh=6 # TCP - final_packet=ip_packet/ext_hdr + final_packet=old_div(ip_packet,ext_hdr) test6_packets.append(final_packet) # TEST 63 @@ -2749,7 +2756,7 @@ def set_up_ipv6_tests(target): ip_packet=build_default_ipv6(target) ip_packet.hlim=255 icmp_packet=ICMPv6ND_INDSol() # RFC 3122 - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 113 @@ -2780,7 +2787,7 @@ def set_up_ipv6_tests(target): ip_packet=build_default_ipv6(target) icmp_packet=ICMPv6MPSol() # RFC 3122 icmp_packet.id=0x3345 - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 116 @@ -2805,7 +2812,7 @@ def set_up_ipv6_tests(target): icmp_packet.id=0x1632 icmp_packet.code=0 icmp_packet.res=65535 # Component=65535 (all certs) - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 118 @@ -2817,7 +2824,7 @@ def set_up_ipv6_tests(target): icmp_packet.id=0x1632 icmp_packet.code=0 icmp_packet.res=65530 # Component=65530 (Cert No. 65530) - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 119 @@ -2829,7 +2836,7 @@ def set_up_ipv6_tests(target): icmp_packet.id=0 # From RFC 3971: the Identifier field MUST NOT be zero icmp_packet.code=0 icmp_packet.res=65535 # Component=65535 (all certs) - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 120 @@ -2839,7 +2846,7 @@ def set_up_ipv6_tests(target): icmp_packet=build_default_icmpv6() icmp_packet.seq=get_icmp_seq_number() icmp_packet.cksum=0x4444 - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 121 @@ -2849,7 +2856,7 @@ def set_up_ipv6_tests(target): icmp_packet=build_default_icmpv6() icmp_packet.seq=get_icmp_seq_number() icmp_packet.cksum=0x0000 - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 122 @@ -2883,7 +2890,7 @@ def set_up_ipv6_tests(target): icmp_packet=build_default_icmpv6() icmp_packet.seq=get_icmp_seq_number() icmp_packet.data="\x16"*32 - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) final_packet.plen=0 test6_packets.append(final_packet) @@ -2934,7 +2941,7 @@ def set_up_ipv6_tests(target): ip_packet=build_default_ipv6(target) ip_packet.nh=255 # IANA Reserverd protocol value payload="\x3b" + "\x11"*31 - final_packet=ip_packet/payload + final_packet=old_div(ip_packet,payload) test6_packets.append(final_packet) # TEST 129 @@ -2943,7 +2950,7 @@ def set_up_ipv6_tests(target): ip_packet=build_default_ipv6(target) ip_packet.nh=140 # Shim6 payload="\x3b\x00\x81" + "\x00"*6 - final_packet=ip_packet/payload + final_packet=old_div(ip_packet,payload) test6_packets.append(final_packet) # TEST 130 @@ -2951,7 +2958,7 @@ def set_up_ipv6_tests(target): test6_descriptions.append("IPv6/MobileIPv6 (Binding Refresh Request)") ip_packet=build_default_ipv6(target) payload=MIP6MH_BRR() - final_packet=ip_packet/payload + final_packet=old_div(ip_packet,payload) test6_packets.append(final_packet) # TEST 131 @@ -2959,7 +2966,7 @@ def set_up_ipv6_tests(target): test6_descriptions.append("IPv6/MobileIPv6 (Home Test Init)") ip_packet=build_default_ipv6(target) payload=MIP6MH_HoTI() - final_packet=ip_packet/payload + final_packet=old_div(ip_packet,payload) test6_packets.append(final_packet) # TEST 132 @@ -2967,7 +2974,7 @@ def set_up_ipv6_tests(target): test6_descriptions.append("IPv6/MobileIPv6 (Care-of Test Init)") ip_packet=build_default_ipv6(target) payload=MIP6MH_CoTI() - final_packet=ip_packet/payload + final_packet=old_div(ip_packet,payload) test6_packets.append(final_packet) # TEST 133 @@ -2991,7 +2998,7 @@ def set_up_ipv6_tests(target): # From RFC=3775: the Header Len field in the Mobility Header MUST NOT be less # than the length specified for this particular type of message in mobile6.len=0 - final_packet=ip_packet/mobile6 + final_packet=old_div(ip_packet,mobile6) test6_packets.append(final_packet) # TEST 135 @@ -3013,7 +3020,7 @@ def set_up_ipv6_tests(target): icmp_packet=build_default_icmpv6() icmp_packet.seq=get_icmp_seq_number() icmp_packet.data="\x19"*32 - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 137 @@ -3024,7 +3031,7 @@ def set_up_ipv6_tests(target): icmp_packet=build_default_icmpv6() icmp_packet.seq=get_icmp_seq_number() icmp_packet.data="\x1A"*32 - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 138 @@ -3036,7 +3043,7 @@ def set_up_ipv6_tests(target): tcp_packet.dport=open_port_g tcp_packet.sport=get_source_port_number() tcp_packet.flags='S' - final_packet=ip_packet/tcp_packet + final_packet=old_div(ip_packet,tcp_packet) test6_packets.append(final_packet) # TEST 139 @@ -3048,7 +3055,7 @@ def set_up_ipv6_tests(target): tcp_packet.dport=open_port_g tcp_packet.sport=get_source_port_number() tcp_packet.flags='S' - final_packet=ip_packet/tcp_packet + final_packet=old_div(ip_packet,tcp_packet) test6_packets.append(final_packet) # TEST 140 @@ -3083,7 +3090,7 @@ def set_up_ipv6_tests(target): icmp_packet=build_default_icmpv6() icmp_packet.seq=get_icmp_seq_number() icmp_packet.data="\x1D"*32 - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 143 @@ -3095,7 +3102,7 @@ def set_up_ipv6_tests(target): tcp_packet.dport=open_port_g tcp_packet.sport=get_source_port_number() tcp_packet.flags='S' - final_packet=ip_packet/tcp_packet + final_packet=old_div(ip_packet,tcp_packet) test6_packets.append(final_packet) # TEST 144 @@ -3166,7 +3173,7 @@ def set_up_ipv6_tests(target): icmp_packet.R=1 icmp_packet.code=0 icmp_packet.tgt=target; - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 148 @@ -3178,7 +3185,7 @@ def set_up_ipv6_tests(target): icmp_packet.S=1 icmp_packet.code=0 icmp_packet.tgt=target; - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 149 @@ -3190,7 +3197,7 @@ def set_up_ipv6_tests(target): icmp_packet.O=1 icmp_packet.code=0 icmp_packet.tgt=target; - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 150 @@ -3204,7 +3211,7 @@ def set_up_ipv6_tests(target): icmp_packet.O=1 icmp_packet.code=0 icmp_packet.tgt=target; - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test6_packets.append(final_packet) # TEST 151 @@ -3216,7 +3223,7 @@ def set_up_ipv6_tests(target): tcp_packet.sport=get_source_port_number() tcp_packet.flags='S' tcp_packet.options=[(0x1c, '\x80\x01')] # TCP UTO with timeout=1min - final_packet=ip_packet/tcp_packet + final_packet=old_div(ip_packet,tcp_packet) test6_packets.append(final_packet) # TEST 152 @@ -3228,7 +3235,7 @@ def set_up_ipv6_tests(target): tcp_packet.sport=get_source_port_number() tcp_packet.flags='S' tcp_packet.options=[(0x1c, '\x00\x00')] # Timeout=0secs - final_packet=ip_packet/tcp_packet + final_packet=old_div(ip_packet,tcp_packet) test6_packets.append(final_packet) # TEST 153 @@ -3240,7 +3247,7 @@ def set_up_ipv6_tests(target): tcp_packet.sport=get_source_port_number() tcp_packet.flags='S' tcp_packet.options=[(0x1d, '\x01\x01\x0F\x0E\x0D\x0C\x0B\x0A\x09\x08\x07\x06\x05\x04\x03\x02\x01\x00')] - final_packet=ip_packet/tcp_packet + final_packet=old_div(ip_packet,tcp_packet) test6_packets.append(final_packet) # TEST 154 @@ -3260,7 +3267,7 @@ def set_up_ipv6_tests(target): # # For more info, check "SPACE COMMUNICATIONS PROTOCOL SPECIFICATION (SCPS), CCSDS 714.0-B-2" tcp_packet.options=[(0x14, '\xF0\x01')] - final_packet=ip_packet/tcp_packet + final_packet=old_div(ip_packet,tcp_packet) test6_packets.append(final_packet) def set_up_ipv4_tests(target): @@ -3280,9 +3287,9 @@ def set_up_ipv4_tests(target): tcp_packet.seq=tcpSeqBase+0 tcp_packet.ack=tcpAck tcp_packet.flags='S' - tcp_packet.options=[('WScale', 10), ('NOP', None), ('MSS',1460), ('Timestamp', (0xFFFFFFFF,0L)), ('SAckOK', '')] + tcp_packet.options=[('WScale', 10), ('NOP', None), ('MSS',1460), ('Timestamp', (0xFFFFFFFF,0)), ('SAckOK', '')] tcp_packet.window=1 - final_packet=ip_packet/tcp_packet + final_packet=old_div(ip_packet,tcp_packet) test4_packets.append(final_packet) # TEST 1 @@ -3300,9 +3307,9 @@ def set_up_ipv4_tests(target): tcp_packet.seq=tcpSeqBase+1 tcp_packet.ack=tcpAck tcp_packet.flags='S' - tcp_packet.options=[('MSS', 1400), ('WScale', 0), ('SAckOK', ''), ('Timestamp', (0xFFFFFFFF,0L)), ('EOL', '')] + tcp_packet.options=[('MSS', 1400), ('WScale', 0), ('SAckOK', ''), ('Timestamp', (0xFFFFFFFF,0)), ('EOL', '')] tcp_packet.window=63 - final_packet=ip_packet/tcp_packet + final_packet=old_div(ip_packet,tcp_packet) test4_packets.append(final_packet) # TEST 2 @@ -3320,9 +3327,9 @@ def set_up_ipv4_tests(target): tcp_packet.seq=tcpSeqBase+2 tcp_packet.ack=tcpAck tcp_packet.flags='S' - tcp_packet.options=[('Timestamp', (0xFFFFFFFF,0L)), ('NOP', ''), ('NOP', ''), ('WScale', 5), ('NOP', ''), ('MSS', 640)] + tcp_packet.options=[('Timestamp', (0xFFFFFFFF,0)), ('NOP', ''), ('NOP', ''), ('WScale', 5), ('NOP', ''), ('MSS', 640)] tcp_packet.window=4 - final_packet=ip_packet/tcp_packet + final_packet=old_div(ip_packet,tcp_packet) test4_packets.append(final_packet) # TEST 3 @@ -3340,9 +3347,9 @@ def set_up_ipv4_tests(target): tcp_packet.seq=tcpSeqBase+3 tcp_packet.ack=tcpAck tcp_packet.flags='S' - tcp_packet.options=[('SAckOK', ''), ('Timestamp', (0xFFFFFFFF,0L)), ('WScale', 10), ('EOL', '')] + tcp_packet.options=[('SAckOK', ''), ('Timestamp', (0xFFFFFFFF,0)), ('WScale', 10), ('EOL', '')] tcp_packet.window=4 - final_packet=ip_packet/tcp_packet + final_packet=old_div(ip_packet,tcp_packet) test4_packets.append(final_packet) # TEST 4 @@ -3360,9 +3367,9 @@ def set_up_ipv4_tests(target): tcp_packet.seq=tcpSeqBase+4 tcp_packet.ack=tcpAck tcp_packet.flags='S' - tcp_packet.options=[('MSS', 536), ('SAckOK', ''), ('Timestamp', (0xFFFFFFFF,0L)), ('WScale', 10), ('EOL', '')] + tcp_packet.options=[('MSS', 536), ('SAckOK', ''), ('Timestamp', (0xFFFFFFFF,0)), ('WScale', 10), ('EOL', '')] tcp_packet.window=16 - final_packet=ip_packet/tcp_packet + final_packet=old_div(ip_packet,tcp_packet) test4_packets.append(final_packet) # TEST 5 @@ -3380,9 +3387,9 @@ def set_up_ipv4_tests(target): tcp_packet.seq=tcpSeqBase+5 tcp_packet.ack=tcpAck tcp_packet.flags='S' - tcp_packet.options=[('MSS', 265), ('SAckOK', ''), ('Timestamp', (0xFFFFFFFF,0L))] + tcp_packet.options=[('MSS', 265), ('SAckOK', ''), ('Timestamp', (0xFFFFFFFF,0))] tcp_packet.window=512 - final_packet=ip_packet/tcp_packet + final_packet=old_div(ip_packet,tcp_packet) test4_packets.append(final_packet) # TEST 6 ECN @@ -3403,7 +3410,7 @@ def set_up_ipv4_tests(target): tcp_packet.flags='CES' tcp_packet.options=[('WScale', 10), ('NOP', ''), ('MSS', 1460), ('SAckOK', ''), ('NOP', ''), ('NOP', '')] tcp_packet.window=3 - final_packet=ip_packet/tcp_packet + final_packet=old_div(ip_packet,tcp_packet) test4_packets.append(final_packet) # TEST 7 (T2) @@ -3422,9 +3429,9 @@ def set_up_ipv4_tests(target): tcp_packet.ack=tcpAck tcp_packet.urgptr=0 tcp_packet.flags='' - tcp_packet.options=[('WScale', 10), ('NOP', ''), ('MSS', 265), ('Timestamp', (0xFFFFFFFF,0L)), ('SAckOK', '')] + tcp_packet.options=[('WScale', 10), ('NOP', ''), ('MSS', 265), ('Timestamp', (0xFFFFFFFF,0)), ('SAckOK', '')] tcp_packet.window=128 - final_packet=ip_packet/tcp_packet + final_packet=old_div(ip_packet,tcp_packet) test4_packets.append(final_packet) # TEST 8 (T3) @@ -3443,9 +3450,9 @@ def set_up_ipv4_tests(target): tcp_packet.ack=tcpAck tcp_packet.urgptr=0 tcp_packet.flags='SFUP' - tcp_packet.options=[('WScale', 10), ('NOP', ''), ('MSS', 265), ('Timestamp', (0xFFFFFFFF,0L)), ('SAckOK', '')] + tcp_packet.options=[('WScale', 10), ('NOP', ''), ('MSS', 265), ('Timestamp', (0xFFFFFFFF,0)), ('SAckOK', '')] tcp_packet.window=256 - final_packet=ip_packet/tcp_packet + final_packet=old_div(ip_packet,tcp_packet) test4_packets.append(final_packet) # TEST 9 (T4) @@ -3464,9 +3471,9 @@ def set_up_ipv4_tests(target): tcp_packet.ack=tcpAck tcp_packet.urgptr=0 tcp_packet.flags='A' - tcp_packet.options=[('WScale', 10), ('NOP', ''), ('MSS', 265), ('Timestamp', (0xFFFFFFFF,0L)), ('SAckOK', '')] + tcp_packet.options=[('WScale', 10), ('NOP', ''), ('MSS', 265), ('Timestamp', (0xFFFFFFFF,0)), ('SAckOK', '')] tcp_packet.window=1024 - final_packet=ip_packet/tcp_packet + final_packet=old_div(ip_packet,tcp_packet) test4_packets.append(final_packet) # TEST 10 (T5) @@ -3485,9 +3492,9 @@ def set_up_ipv4_tests(target): tcp_packet.ack=tcpAck tcp_packet.urgptr=0 tcp_packet.flags='S' - tcp_packet.options=[('WScale', 10), ('NOP', ''), ('MSS', 265), ('Timestamp', (0xFFFFFFFF,0L)), ('SAckOK', '')] + tcp_packet.options=[('WScale', 10), ('NOP', ''), ('MSS', 265), ('Timestamp', (0xFFFFFFFF,0)), ('SAckOK', '')] tcp_packet.window=31337 - final_packet=ip_packet/tcp_packet + final_packet=old_div(ip_packet,tcp_packet) test4_packets.append(final_packet) # TEST 11 (T6) @@ -3506,9 +3513,9 @@ def set_up_ipv4_tests(target): tcp_packet.ack=tcpAck tcp_packet.urgptr=0 tcp_packet.flags='A' - tcp_packet.options=[('WScale', 10), ('NOP', ''), ('MSS', 265), ('Timestamp', (0xFFFFFFFF,0L)), ('SAckOK', '')] + tcp_packet.options=[('WScale', 10), ('NOP', ''), ('MSS', 265), ('Timestamp', (0xFFFFFFFF,0)), ('SAckOK', '')] tcp_packet.window=32768 - final_packet=ip_packet/tcp_packet + final_packet=old_div(ip_packet,tcp_packet) test4_packets.append(final_packet) # TEST 12 (T7) @@ -3527,9 +3534,9 @@ def set_up_ipv4_tests(target): tcp_packet.ack=tcpAck tcp_packet.urgptr=0 tcp_packet.flags='FPU' - tcp_packet.options=[('WScale', 15), ('NOP', ''), ('MSS', 265), ('Timestamp', (0xFFFFFFFF,0L)), ('SAckOK', '')] + tcp_packet.options=[('WScale', 15), ('NOP', ''), ('MSS', 265), ('Timestamp', (0xFFFFFFFF,0)), ('SAckOK', '')] tcp_packet.window=65535 - final_packet=ip_packet/tcp_packet + final_packet=old_div(ip_packet,tcp_packet) test4_packets.append(final_packet) # TEST 13 (IE 1) @@ -3546,7 +3553,7 @@ def set_up_ipv4_tests(target): icmp_packet.seq=295 icmp_packet.id=0xABCD icmp_packet.data='\x00'*120 - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test4_packets.append(final_packet) # TEST 14 (IE 2) @@ -3563,7 +3570,7 @@ def set_up_ipv4_tests(target): icmp_packet.seq=295+1 icmp_packet.id=0xABCD+1 icmp_packet.data='\x00'*150 - final_packet=ip_packet/icmp_packet + final_packet=old_div(ip_packet,icmp_packet) test4_packets.append(final_packet) # TEST 15 (U1) @@ -3653,7 +3660,7 @@ def get_target_mac_address(target, interface): try: target_tmp = inet_pton(AF_INET6, target) except socket.error: - print "inet_pton() failed on get_target_mac_address() - sigh." + print("inet_pton() failed on get_target_mac_address() - sigh.") byte_13 = hex(unpack('B', target_tmp[13])[0])[2:] byte_14 = hex(unpack('B', target_tmp[14])[0])[2:] @@ -3785,7 +3792,7 @@ def argparser(): def interactive_mode(): global interface_g, send_eth_g, target_host6_g, target_host4_g, target_os_details_g, open_port_g, closed_port_g - print "[+] First of all, we need you to provide some details:" + print("[+] First of all, we need you to provide some details:") # Request target's IPv6 Address target_host6_g=ask_interactive_target_addr6() @@ -3806,13 +3813,13 @@ def interactive_mode(): def ask_interactive_target_addr6(): while True: - addr=raw_input(" |_ Target's IPv6 address: ") + addr=eval(input(" |_ Target's IPv6 address: ")) if addr!=None and len(addr)>0 : break return addr def ask_interactive_target_addr4(): - addr=raw_input(" |_ Target's IP (version 4) address [Press ENTER to skip IPv4]: ") + addr=eval(input(" |_ Target's IP (version 4) address [Press ENTER to skip IPv4]: ")) if addr==None or len(addr)==0 : return None else : @@ -3820,15 +3827,15 @@ def ask_interactive_target_addr4(): def ask_interactive_interface(): while True: - print " |_ Supplied IPv6 address is link-local. Please specify which" - iface=raw_input(" network interface should be used: ") + print(" |_ Supplied IPv6 address is link-local. Please specify which") + iface=eval(input(" network interface should be used: ")) if iface!=None and len(iface)>0 : break return iface def ask_interactive_openport(): while True: - port=raw_input(" |_ OPEN port in target [Press ENTER to default to "+str(DEFAULT_OPEN_PORT_IN_TARGET)+"]: ") + port=eval(input(" |_ OPEN port in target [Press ENTER to default to "+str(DEFAULT_OPEN_PORT_IN_TARGET)+"]: ")) if port==None or len(port)==0 : return DEFAULT_OPEN_PORT_IN_TARGET elif port.isdigit() : @@ -3836,7 +3843,7 @@ def ask_interactive_openport(): def ask_interactive_closedport(): while True: - port=raw_input(" |_ CLOSED port in target [Press ENTER to default to "+str(DEFAULT_CLOSED_PORT_IN_TARGET)+"]: ") + port=eval(input(" |_ CLOSED port in target [Press ENTER to default to "+str(DEFAULT_CLOSED_PORT_IN_TARGET)+"]: ")) if port==None or len(port)==0 : return DEFAULT_CLOSED_PORT_IN_TARGET elif port.isdigit() : @@ -3855,11 +3862,11 @@ def ask_interactive_osdetails(): while True : # Request OS type - print "==================TARGET OS TYPES ==================" + print("==================TARGET OS TYPES ==================") for i in range(0, len(os)): - print " " + str(i) + ") " + os[i][0] + print(" " + str(i) + ") " + os[i][0]) while True: - os_type=raw_input("[+] Please enter the target's OS type: ") + os_type=eval(input("[+] Please enter the target's OS type: ")) if len(os_type)<=0 or os_type.isdigit()==False: os_type=-1 else : @@ -3868,42 +3875,42 @@ def ask_interactive_osdetails(): break # Request OS sub-type - print "================TARGET OS SUB-TYPES ================" + print("================TARGET OS SUB-TYPES ================") for i in range(0, len(os[os_type][1])): - print " " + str(i) + ") " + os[os_type][1][i] + print(" " + str(i) + ") " + os[os_type][1][i]) while True: - os_subtype=raw_input("[+] Please enter the target's OS sub type: ") + os_subtype=eval(input("[+] Please enter the target's OS sub type: ")) if len(os_subtype)<=0 or os_subtype.isdigit()==False: os_subtype=-1 else : os_subtype=int(os_subtype) if os_subtype>=0 and os_subtype>> Updating %s" % os.path.join(base_dir, VERSION) + print(">>> Updating %s" % os.path.join(base_dir, VERSION)) vf = open(os.path.join(base_dir, VERSION), "wb") - print >> vf, version + print(version, file=vf) vf.close() - print ">>> Updating %s" % os.path.join(base_dir, VERSION_PY) + print(">>> Updating %s" % os.path.join(base_dir, VERSION_PY)) vf = open(os.path.join(base_dir, VERSION_PY), "w") - print >> vf, "VERSION = \"%s\"" % version + print("VERSION = \"%s\"" % version, file=vf) vf.close() if __name__ == "__main__": if len(sys.argv) != 2: - print >> sys.stderr, "Usage: %s " % sys.argv[0] + print("Usage: %s " % sys.argv[0], file=sys.stderr) sys.exit(1) version = sys.argv[1] - print ">>> Updating version number to \"%s\"" % version + print(">>> Updating version number to \"%s\"" % version) update_version(".", version) diff --git a/zenmap/radialnet/bestwidgets/textview.py b/zenmap/radialnet/bestwidgets/textview.py index bbdfb1e..0d2a069 100644 --- a/zenmap/radialnet/bestwidgets/textview.py +++ b/zenmap/radialnet/bestwidgets/textview.py @@ -125,6 +125,8 @@ # * * # ***************************************************************************/ +from builtins import str +from builtins import range import gtk from radialnet.bestwidgets.boxes import * @@ -250,7 +252,7 @@ class BWTextEditor(BWScrolledWindow): count = text.count('\n') + text.count('\r') - lines = range(1, count + 2) + lines = list(range(1, count + 2)) lines = [str(i).strip() for i in lines] self.__textbuffer.set_text(text) diff --git a/zenmap/radialnet/core/ArgvHandle.py b/zenmap/radialnet/core/ArgvHandle.py index 99af401..2e0f055 100644 --- a/zenmap/radialnet/core/ArgvHandle.py +++ b/zenmap/radialnet/core/ArgvHandle.py @@ -125,10 +125,12 @@ # * * # ***************************************************************************/ +from __future__ import print_function +from builtins import object import sys -class ArgvHandle: +class ArgvHandle(object): """ """ def __init__(self, argv): @@ -165,4 +167,4 @@ if __name__ == '__main__': h = ArgvHandle(sys.argv) - print h.get_last_value() + print(h.get_last_value()) diff --git a/zenmap/radialnet/core/Coordinate.py b/zenmap/radialnet/core/Coordinate.py index 610a56f..c46fd6b 100644 --- a/zenmap/radialnet/core/Coordinate.py +++ b/zenmap/radialnet/core/Coordinate.py @@ -125,10 +125,14 @@ # * * # ***************************************************************************/ +from __future__ import division +from __future__ import print_function +from past.utils import old_div +from builtins import object import math -class PolarCoordinate: +class PolarCoordinate(object): """ Class to implement a polar coordinate object """ @@ -198,7 +202,7 @@ class PolarCoordinate: return (x, y) -class CartesianCoordinate: +class CartesianCoordinate(object): """ Class to implement a cartesian coordinate object """ @@ -245,13 +249,13 @@ class CartesianCoordinate: if self.__x > 0: if self.__y >= 0: - t = math.atan(self.__y / self.__x) + t = math.atan(old_div(self.__y, self.__x)) else: - t = math.atan(self.__y / self.__x) + 2 * math.pi + t = math.atan(old_div(self.__y, self.__x)) + 2 * math.pi elif self.__x < 0: - t = math.atan(self.__y / self.__x) + math.pi + t = math.atan(old_div(self.__y, self.__x)) + math.pi elif self.__x == 0: @@ -259,10 +263,10 @@ class CartesianCoordinate: t = 0 if self.__y > 0: - t = math.pi / 2 + t = old_div(math.pi, 2) else: - t = -math.pi / 2 + t = old_div(-math.pi, 2) return (r, t) @@ -274,5 +278,5 @@ if __name__ == "__main__": polar = PolarCoordinate(1, math.pi) cartesian = CartesianCoordinate(-1, 0) - print polar.to_cartesian() - print cartesian.to_polar() + print(polar.to_cartesian()) + print(cartesian.to_polar()) diff --git a/zenmap/radialnet/core/Graph.py b/zenmap/radialnet/core/Graph.py index 0e248aa..973d0b9 100644 --- a/zenmap/radialnet/core/Graph.py +++ b/zenmap/radialnet/core/Graph.py @@ -126,6 +126,9 @@ # ***************************************************************************/ +from __future__ import division +from past.utils import old_div +from builtins import object class Node(object): """ Node class @@ -166,7 +169,7 @@ class Node(object): self.__edges.append(edge) -class Edge: +class Edge(object): """ """ def __init__(self, nodes): @@ -190,13 +193,13 @@ class Edge: """ """ self.__weights = weights - self.__weights_mean = sum(self.__weights) / len(self.__weights) + self.__weights_mean = old_div(sum(self.__weights), len(self.__weights)) def add_weight(self, weight): """ """ self.__weights.append(weight) - self.__weights_mean = sum(self.__weights) / len(self.__weights) + self.__weights_mean = old_div(sum(self.__weights), len(self.__weights)) def get_weights_mean(self): """ @@ -204,7 +207,7 @@ class Edge: return self.__weights_mean -class Graph: +class Graph(object): """ Network Graph class """ diff --git a/zenmap/radialnet/core/Interpolation.py b/zenmap/radialnet/core/Interpolation.py index 15b1ca6..57793f7 100644 --- a/zenmap/radialnet/core/Interpolation.py +++ b/zenmap/radialnet/core/Interpolation.py @@ -126,7 +126,12 @@ # ***************************************************************************/ -class Linear2DInterpolator: +from __future__ import division +from __future__ import print_function +from builtins import range +from builtins import object +from past.utils import old_div +class Linear2DInterpolator(object): """ Implements a bidimensional linear interpolator. """ @@ -175,13 +180,13 @@ class Linear2DInterpolator: (ai, bi) = self.__start_point (af, bf) = self.__final_point - a_conversion_factor = float(af - ai) / sum(pass_vector) - b_conversion_factor = float(bf - bi) / sum(pass_vector) + a_conversion_factor = old_div(float(af - ai), sum(pass_vector)) + b_conversion_factor = old_div(float(bf - bi), sum(pass_vector)) a_pass = 0 b_pass = 0 - self.__interpolated_points = range(number_of_pass) + self.__interpolated_points = list(range(number_of_pass)) for i in range(0, number_of_pass): @@ -203,10 +208,10 @@ class Linear2DInterpolator: (ai, bi) = self.__start_point (af, bf) = self.__final_point - a_pass = float(af - ai) / number_of_pass - b_pass = float(bf - bi) / number_of_pass + a_pass = old_div(float(af - ai), number_of_pass) + b_pass = old_div(float(bf - bi), number_of_pass) - self.__interpolated_points = range(number_of_pass) + self.__interpolated_points = list(range(number_of_pass)) for i in range(1, number_of_pass + 1): self.__interpolated_points[i - 1] = (ai + a_pass * i, @@ -224,4 +229,4 @@ if __name__ == "__main__": i.set_start_point(0, 0) i.set_final_point(1, 1) - print len(i.get_points(10)), i.get_points(10) + print(len(i.get_points(10)), i.get_points(10)) diff --git a/zenmap/radialnet/core/XMLHandler.py b/zenmap/radialnet/core/XMLHandler.py index 6d17666..706120c 100644 --- a/zenmap/radialnet/core/XMLHandler.py +++ b/zenmap/radialnet/core/XMLHandler.py @@ -127,6 +127,8 @@ # Prevent loading PyXML +from builtins import str +from builtins import object import xml xml.__path__ = [x for x in xml.__path__ if "_xmlplus" not in x] @@ -141,7 +143,7 @@ def convert_to_utf8(text): return text.encode('utf8', 'replace') -class XMLNode: +class XMLNode(object): """ """ def __init__(self, name): @@ -185,7 +187,7 @@ class XMLNode: def get_keys(self): """ """ - return self.__attrs.keys() + return list(self.__attrs.keys()) def get_attr(self, attr): """ diff --git a/zenmap/radialnet/gui/Application.py b/zenmap/radialnet/gui/Application.py index 9e39eaa..c62383c 100644 --- a/zenmap/radialnet/gui/Application.py +++ b/zenmap/radialnet/gui/Application.py @@ -125,17 +125,18 @@ # * * # ***************************************************************************/ +from __future__ import absolute_import import gtk -from radialnet.util.integration import make_graph_from_nmap_parser -from radialnet.core.Info import INFO -from radialnet.core.XMLHandler import XMLReader -from radialnet.gui.ControlWidget import ControlWidget, ControlFisheye -from radialnet.gui.Toolbar import Toolbar -from radialnet.gui.Image import Pixmaps -from radialnet.gui.RadialNet import * -from radialnet.bestwidgets.windows import * -from radialnet.bestwidgets.boxes import * +from .radialnet.util.integration import make_graph_from_nmap_parser +from .radialnet.core.Info import INFO +from .radialnet.core.XMLHandler import XMLReader +from .radialnet.gui.ControlWidget import ControlWidget, ControlFisheye +from .radialnet.gui.Toolbar import Toolbar +from .radialnet.gui.Image import Pixmaps +from .radialnet.gui.RadialNet import * +from .radialnet.bestwidgets.windows import * +from .radialnet.bestwidgets.boxes import * DIMENSION = (640, 480) diff --git a/zenmap/radialnet/gui/ControlWidget.py b/zenmap/radialnet/gui/ControlWidget.py index 3462390..a3b519b 100644 --- a/zenmap/radialnet/gui/ControlWidget.py +++ b/zenmap/radialnet/gui/ControlWidget.py @@ -125,17 +125,22 @@ # * * # ***************************************************************************/ +from __future__ import division +from __future__ import absolute_import +from builtins import str +from builtins import range +from past.utils import old_div import gtk import math import gobject -import radialnet.util.drawing as drawing -import radialnet.util.geometry as geometry +from . import radialnet.util.drawing as drawing +from . import radialnet.util.geometry as geometry -from radialnet.bestwidgets.boxes import * -from radialnet.core.Coordinate import PolarCoordinate -from radialnet.gui.RadialNet import * -from radialnet.bestwidgets.expanders import BWExpander +from .radialnet.bestwidgets.boxes import * +from .radialnet.core.Coordinate import PolarCoordinate +from .radialnet.gui.RadialNet import * +from .radialnet.bestwidgets.expanders import BWExpander OPTIONS = ['address', @@ -382,8 +387,8 @@ class ControlVariableWidget(gtk.DrawingArea): """ allocation = self.get_allocation() - self.__center_of_widget = (allocation.width / 2, - allocation.height / 2) + self.__center_of_widget = (old_div(allocation.width, 2), + old_div(allocation.height, 2)) xc, yc = self.__center_of_widget @@ -434,7 +439,7 @@ class ControlVariableWidget(gtk.DrawingArea): def __increment_value(self): """ """ - self.__update(self.__value() + self.__pointer_position / 4) + self.__update(self.__value() + old_div(self.__pointer_position, 4)) self.queue_draw() @@ -1298,8 +1303,8 @@ class ControlNavigation(gtk.DrawingArea): # Getting allocation reference allocation = self.get_allocation() - self.__center_of_widget = (allocation.width / 2, - allocation.height / 2) + self.__center_of_widget = (old_div(allocation.width, 2), + old_div(allocation.height, 2)) self.__draw_rotate_control() self.__draw_move_control() diff --git a/zenmap/radialnet/gui/Dialogs.py b/zenmap/radialnet/gui/Dialogs.py index 56cb668..35de83e 100644 --- a/zenmap/radialnet/gui/Dialogs.py +++ b/zenmap/radialnet/gui/Dialogs.py @@ -125,11 +125,12 @@ # * * # ***************************************************************************/ +from __future__ import absolute_import import gtk import pango -from radialnet.core.Info import INFO -from radialnet.gui.Image import Pixmaps +from .radialnet.core.Info import INFO +from .radialnet.gui.Image import Pixmaps class AboutDialog(gtk.AboutDialog): diff --git a/zenmap/radialnet/gui/HostsViewer.py b/zenmap/radialnet/gui/HostsViewer.py index 4411df1..1f67396 100644 --- a/zenmap/radialnet/gui/HostsViewer.py +++ b/zenmap/radialnet/gui/HostsViewer.py @@ -125,14 +125,18 @@ # * * # ***************************************************************************/ +from __future__ import division +from __future__ import absolute_import +from builtins import range +from past.utils import old_div import re import gtk import gobject -from radialnet.bestwidgets.windows import * +from .radialnet.bestwidgets.windows import * -from radialnet.gui.NodeNotebook import NodeNotebook -from radialnet.util.misc import ipv4_compare +from .radialnet.gui.NodeNotebook import NodeNotebook +from .radialnet.util.misc import ipv4_compare HOSTS_COLORS = ['#d5ffd5', '#ffffd5', '#ffd5d5'] @@ -170,7 +174,7 @@ class HostsViewer(BWMainWindow): self.__panel.add1(self.__list) self.__panel.add2(self.__view) - self.__panel.set_position(int(DIMENSION[0] / 5)) + self.__panel.set_position(int(old_div(DIMENSION[0], 5))) self.add(self.__panel) diff --git a/zenmap/radialnet/gui/Image.py b/zenmap/radialnet/gui/Image.py index 4a97156..a69bb37 100644 --- a/zenmap/radialnet/gui/Image.py +++ b/zenmap/radialnet/gui/Image.py @@ -125,6 +125,9 @@ # * * # ***************************************************************************/ +from __future__ import division +from builtins import object +from past.utils import old_div import os import sys import gtk @@ -144,7 +147,7 @@ def get_pixels_for_cairo_image_surface(pixbuf): cairo.ImageSurface.create_for_data() method. """ data = array.ArrayType('c') - format = pixbuf.get_rowstride() / pixbuf.get_width() + format = old_div(pixbuf.get_rowstride(), pixbuf.get_width()) i = 0 j = 0 @@ -167,7 +170,7 @@ def get_pixels_for_cairo_image_surface(pixbuf): return (FORMAT_RGBA * pixbuf.get_width(), data) -class Image: +class Image(object): """ """ def __init__(self, path=None): @@ -187,7 +190,7 @@ class Image: if self.__path is None: return False - if icon + image_type not in self.__cache.keys(): + if icon + image_type not in list(self.__cache.keys()): file = self.get_icon(icon, image_type) self.__cache[icon + image_type] = \ diff --git a/zenmap/radialnet/gui/LegendWindow.py b/zenmap/radialnet/gui/LegendWindow.py index b61383c..344e8f9 100644 --- a/zenmap/radialnet/gui/LegendWindow.py +++ b/zenmap/radialnet/gui/LegendWindow.py @@ -125,20 +125,23 @@ # * * # ***************************************************************************/ +from __future__ import division +from __future__ import absolute_import +from past.utils import old_div import gtk import pango import math import cairo import zenmapCore.I18N -import radialnet.util.drawing as drawing - -from radialnet.bestwidgets.windows import * -from radialnet.bestwidgets.boxes import * -from radialnet.bestwidgets.labels import * -from radialnet.gui.Image import Pixmaps -from radialnet.gui.NodeNotebook import NodeNotebook -from radialnet.util.drawing import * +from . import radialnet.util.drawing as drawing + +from .radialnet.bestwidgets.windows import * +from .radialnet.bestwidgets.boxes import * +from .radialnet.bestwidgets.labels import * +from .radialnet.gui.Image import Pixmaps +from .radialnet.gui.NodeNotebook import NodeNotebook +from .radialnet.util.drawing import * DIMENSION_NORMAL = (350, 450) @@ -180,7 +183,7 @@ def draw_circle(context, x, y, size, color, label): def draw_square(context, x, y, size, color): context.set_source_rgb(0, 0, 0) - context.rectangle(x, y - size / 2, size, size) + context.rectangle(x, y - old_div(size, 2), size, size) context.stroke_preserve() context.set_source_rgb(*color) context.fill() diff --git a/zenmap/radialnet/gui/NodeNotebook.py b/zenmap/radialnet/gui/NodeNotebook.py index a0b4707..49eea11 100644 --- a/zenmap/radialnet/gui/NodeNotebook.py +++ b/zenmap/radialnet/gui/NodeNotebook.py @@ -125,14 +125,16 @@ # * * # ***************************************************************************/ +from __future__ import absolute_import +from builtins import range import gtk import pango import gobject -from radialnet.bestwidgets.boxes import * -from radialnet.bestwidgets.expanders import BWExpander -from radialnet.bestwidgets.labels import * -from radialnet.bestwidgets.textview import * +from .radialnet.bestwidgets.boxes import * +from .radialnet.bestwidgets.expanders import BWExpander +from .radialnet.bestwidgets.labels import * +from .radialnet.bestwidgets.textview import * import zenmapCore.I18N diff --git a/zenmap/radialnet/gui/NodeWindow.py b/zenmap/radialnet/gui/NodeWindow.py index a8f28af..56ecf59 100644 --- a/zenmap/radialnet/gui/NodeWindow.py +++ b/zenmap/radialnet/gui/NodeWindow.py @@ -125,16 +125,17 @@ # * * # ***************************************************************************/ +from __future__ import absolute_import import gtk import pango -import radialnet.util.drawing as drawing +from . import radialnet.util.drawing as drawing -from radialnet.bestwidgets.windows import * -from radialnet.bestwidgets.boxes import * -from radialnet.bestwidgets.labels import * -from radialnet.gui.Image import Application -from radialnet.gui.NodeNotebook import NodeNotebook +from .radialnet.bestwidgets.windows import * +from .radialnet.bestwidgets.boxes import * +from .radialnet.bestwidgets.labels import * +from .radialnet.gui.Image import Application +from .radialnet.gui.NodeNotebook import NodeNotebook DIMENSION_NORMAL = (600, 400) diff --git a/zenmap/radialnet/gui/RadialNet.py b/zenmap/radialnet/gui/RadialNet.py index eb34ebb..236c0c8 100644 --- a/zenmap/radialnet/gui/RadialNet.py +++ b/zenmap/radialnet/gui/RadialNet.py @@ -125,6 +125,11 @@ # * * # ***************************************************************************/ +from __future__ import division +from __future__ import absolute_import +from builtins import str +from builtins import range +from past.utils import old_div import gtk import math import time @@ -132,17 +137,18 @@ import copy import cairo import gobject -import radialnet.util.drawing as drawing -import radialnet.util.geometry as geometry -import radialnet.util.misc as misc +from . import radialnet.util.drawing as drawing +from . import radialnet.util.geometry as geometry +from . import radialnet.util.misc as misc -from radialnet.core.Coordinate import PolarCoordinate, CartesianCoordinate -from radialnet.core.Interpolation import Linear2DInterpolator -from radialnet.core.Graph import Graph, Node -from radialnet.gui.NodeWindow import NodeWindow -from radialnet.gui.Image import Icons, get_pixels_for_cairo_image_surface +from .radialnet.core.Coordinate import PolarCoordinate, CartesianCoordinate +from .radialnet.core.Interpolation import Linear2DInterpolator +from .radialnet.core.Graph import Graph, Node +from .radialnet.gui.NodeWindow import NodeWindow +from .radialnet.gui.Image import Icons, get_pixels_for_cairo_image_surface from zenmapCore.BasePaths import fs_enc +from functools import reduce REGION_COLORS = [(1.0, 0.0, 0.0), (1.0, 1.0, 0.0), (0.0, 1.0, 0.0)] REGION_RED = 0 @@ -195,7 +201,7 @@ class RadialNet(gtk.DrawingArea): self.__interpolation_slow_in_out = True self.__animating = False - self.__animation_rate = 1000 / 60 # 60Hz (human perception factor) + self.__animation_rate = old_div(1000, 60) # 60Hz (human perception factor) self.__number_of_frames = 60 self.__scale = 1.0 @@ -586,7 +592,7 @@ class RadialNet(gtk.DrawingArea): """ if float(zoom) >= 1: - self.set_scale(float(zoom) / 100.0) + self.set_scale(old_div(float(zoom), 100.0)) self.queue_draw() def get_ring_gap(self): @@ -785,7 +791,7 @@ class RadialNet(gtk.DrawingArea): node, point = result x, y = point - if node in self.__node_views.keys(): + if node in list(self.__node_views.keys()): self.__node_views[node].present() @@ -894,8 +900,8 @@ class RadialNet(gtk.DrawingArea): # getting allocation reference allocation = self.get_allocation() - self.__center_of_widget = (allocation.width / 2, - allocation.height / 2) + self.__center_of_widget = (old_div(allocation.width, 2), + old_div(allocation.height, 2)) aw, ah = allocation.width, allocation.height xc, yc = self.__center_of_widget @@ -1087,8 +1093,8 @@ class RadialNet(gtk.DrawingArea): context.set_font_size(8) context.set_line_width(1) - context.move_to(xc + (xa + xb) / 2 + 1, - yc - (ya + yb) / 2 + 4) + context.move_to(xc + old_div((xa + xb), 2) + 1, + yc - old_div((ya + yb), 2) + 4) context.show_text(str(round(latency, 2))) context.stroke() @@ -1167,7 +1173,7 @@ class RadialNet(gtk.DrawingArea): icons = list() - if type in ICON_DICT.keys(): + if type in list(ICON_DICT.keys()): icons.append(self.__icon.get_pixbuf(ICON_DICT[type])) if node.get_info('filtered'): @@ -1242,7 +1248,7 @@ class RadialNet(gtk.DrawingArea): level_of_detail = self.__ring_gap * self.__fisheye_interest spread_distance = distance - distance * self.__fisheye_spread - value = level_of_detail / (spread_distance + 1) + value = old_div(level_of_detail, (spread_distance + 1)) if value < self.__min_ring_gap: value = self.__min_ring_gap @@ -1413,7 +1419,7 @@ class RadialNet(gtk.DrawingArea): child_need = child.get_draw_info('space_need') child_total = node_total * child_need / children_need - theta = child_total / 2 + min + self.__rotate + theta = old_div(child_total, 2) + min + self.__rotate child.set_coordinate_theta(theta) child.set_draw_info({'range': (min, min + child_total)}) @@ -1441,11 +1447,11 @@ class RadialNet(gtk.DrawingArea): if len(children) > 0: min, max = node.get_draw_info('range') - factor = float(max - min) / len(children) + factor = old_div(float(max - min), len(children)) for child in children: - theta = factor / 2 + min + self.__rotate + theta = old_div(factor, 2) + min + self.__rotate child.set_coordinate_theta(theta) child.set_draw_info({'range': (min, min + factor)}) @@ -1529,9 +1535,9 @@ class RadialNet(gtk.DrawingArea): self.__calc_node_positions() # steps for slow-in/slow-out animation - steps = range(self.__number_of_frames) + steps = list(range(self.__number_of_frames)) - for i in range(len(steps) / 2): + for i in range(old_div(len(steps), 2)): steps[self.__number_of_frames - 1 - i] = steps[i] # normalize angles and calculate interpolated points @@ -1877,7 +1883,7 @@ class NetNode(Node): # If all fields are empty, we don't put it into the sequences # list if reduce(lambda x, y: x + y, - host.tcpsequence.values(), "") != "": + list(host.tcpsequence.values()), "") != "": tcp = {} if host.tcpsequence.get("index", "") != "": tcp["index"] = int(host.tcpsequence["index"]) @@ -1889,14 +1895,14 @@ class NetNode(Node): tcp["difficulty"] = host.tcpsequence.get("difficulty", "") sequences["tcp"] = tcp if reduce(lambda x, y: x + y, - host.ipidsequence.values(), "") != "": + list(host.ipidsequence.values()), "") != "": ip_id = {} ip_id["class"] = host.ipidsequence.get("class", "") ip_id["values"] = host.ipidsequence.get( "values", "").split(",") sequences["ip_id"] = ip_id if reduce(lambda x, y: x + y, - host.tcptssequence.values(), "") != "": + list(host.tcptssequence.values()), "") != "": tcp_ts = {} tcp_ts["class"] = host.tcptssequence.get("class", "") tcp_ts["values"] = host.tcptssequence.get( diff --git a/zenmap/radialnet/gui/SaveDialog.py b/zenmap/radialnet/gui/SaveDialog.py index 90d7922..b0e2ec8 100644 --- a/zenmap/radialnet/gui/SaveDialog.py +++ b/zenmap/radialnet/gui/SaveDialog.py @@ -125,9 +125,10 @@ # * * # ***************************************************************************/ +from __future__ import absolute_import import gtk import os.path -import radialnet.gui.RadialNet as RadialNet +from . import radialnet.gui.RadialNet as RadialNet import zenmapGUI.FileChoosers from zenmapGUI.higwidgets.higboxes import HIGHBox diff --git a/zenmap/radialnet/gui/Toolbar.py b/zenmap/radialnet/gui/Toolbar.py index 8fb750a..4fc09f2 100644 --- a/zenmap/radialnet/gui/Toolbar.py +++ b/zenmap/radialnet/gui/Toolbar.py @@ -125,15 +125,17 @@ # * * # ***************************************************************************/ +from __future__ import absolute_import +from builtins import str import os import gtk import gobject -from radialnet.bestwidgets.buttons import * -from radialnet.gui.SaveDialog import SaveDialog -from radialnet.gui.Dialogs import AboutDialog -from radialnet.gui.LegendWindow import LegendWindow -from radialnet.gui.HostsViewer import HostsViewer +from .radialnet.bestwidgets.buttons import * +from .radialnet.gui.SaveDialog import SaveDialog +from .radialnet.gui.Dialogs import AboutDialog +from .radialnet.gui.LegendWindow import LegendWindow +from .radialnet.gui.HostsViewer import HostsViewer from zenmapGUI.higwidgets.higdialogs import HIGAlertDialog @@ -322,11 +324,11 @@ class Toolbar(gtk.HBox): try: self.radialnet.save_drawing_to_file(filename, filetype) - except Exception, e: + except Exception as e: alert = HIGAlertDialog(parent=self.__save_chooser, type=gtk.MESSAGE_ERROR, message_format=_("Error saving snapshot"), - secondary_text=unicode(e)) + secondary_text=str(e)) alert.run() alert.destroy() diff --git a/zenmap/radialnet/util/drawing.py b/zenmap/radialnet/util/drawing.py index 685097c..54af81b 100644 --- a/zenmap/radialnet/util/drawing.py +++ b/zenmap/radialnet/util/drawing.py @@ -125,13 +125,14 @@ # * * # ***************************************************************************/ +from builtins import range import math def cairo_to_gdk_color(color): """ """ - new_color = range(len(color)) + new_color = list(range(len(color))) for i in range(len(color)): new_color[i] = int(color[i] * 65535) diff --git a/zenmap/radialnet/util/geometry.py b/zenmap/radialnet/util/geometry.py index bfac9b2..e40b07c 100644 --- a/zenmap/radialnet/util/geometry.py +++ b/zenmap/radialnet/util/geometry.py @@ -125,6 +125,8 @@ # * * # ***************************************************************************/ +from __future__ import division +from past.utils import old_div import math @@ -163,7 +165,7 @@ def atan_scale(point, scale_ceil): def normalize_angle(angle): """ """ - new_angle = 360.0 * (float(angle / 360) - int(angle / 360)) + new_angle = 360.0 * (float(old_div(angle, 360)) - int(old_div(angle, 360))) if new_angle < 0: return 360 + new_angle @@ -219,4 +221,4 @@ def calculate_short_path(iangle, fangle): def angle_from_object(distance, size): """ """ - return math.degrees(math.atan2(size / 2.0, distance)) + return math.degrees(math.atan2(old_div(size, 2.0), distance)) diff --git a/zenmap/radialnet/util/integration.py b/zenmap/radialnet/util/integration.py index 657ca49..a3e9978 100644 --- a/zenmap/radialnet/util/integration.py +++ b/zenmap/radialnet/util/integration.py @@ -125,6 +125,8 @@ # * * # ***************************************************************************/ +from builtins import range +from builtins import object from radialnet.core.Graph import * from radialnet.gui.RadialNet import NetNode import zenmapCore.NmapParser diff --git a/zenmap/radialnet/util/misc.py b/zenmap/radialnet/util/misc.py index a52ef76..4ded4e0 100644 --- a/zenmap/radialnet/util/misc.py +++ b/zenmap/radialnet/util/misc.py @@ -125,6 +125,7 @@ # * * # ***************************************************************************/ +from builtins import range from radialnet.core.Coordinate import CartesianCoordinate from radialnet.util.geometry import * import math diff --git a/zenmap/setup.py b/zenmap/setup.py index efb5759..1285cab 100755 --- a/zenmap/setup.py +++ b/zenmap/setup.py @@ -125,9 +125,12 @@ # * Nmap, and also available from https://svn.nmap.org/nmap/COPYING) * # * * # ***************************************************************************/ +from __future__ import print_function +from builtins import str +from builtins import range import sys -if sys.version_info[0] != 2: +if sys.version_info[0] < 2: sys.exit("Sorry, Zenmap requires Python 2") import errno @@ -195,8 +198,7 @@ data_files = [ ] # Add i18n files to data_files list -os.path.walk(locale_dir, mo_find, data_files) - +os.walk(locale_dir, mo_find, data_files) # path_startswith and path_strip_prefix are used to deal with the installation # root (--root option, also known as DESTDIR). @@ -356,7 +358,7 @@ for dir in dirs: uninstaller_file.close() # Set exec bit for uninstaller - mode = ((os.stat(uninstaller_filename)[ST_MODE]) | 0555) & 07777 + mode = ((os.stat(uninstaller_filename)[ST_MODE]) | 0o555) & 0o7777 os.chmod(uninstaller_filename, mode) def set_modules_path(self): @@ -427,7 +429,7 @@ for dir in dirs: break # Replace the path definitions. - for path, replacement in interesting_paths.items(): + for path, replacement in list(interesting_paths.items()): pcontent = re.sub("%s\s+=\s+.+" % path, "%s = %s" % (path, repr(replacement)), pcontent) @@ -489,7 +491,7 @@ for dir in dirs: try: for output in self.get_installed_files(): assert "\n" not in output - print >> f, output + print(output, file=f) finally: f.close() @@ -513,7 +515,7 @@ class my_uninstall(Command): # Read the list of installed files. try: f = open(INSTALLED_FILES_NAME, "r") - except IOError, e: + except IOError as e: if e.errno == errno.ENOENT: log.error("Couldn't open the installation record '%s'. " "Have you installed yet?" % INSTALLED_FILES_NAME) @@ -536,7 +538,7 @@ class my_uninstall(Command): try: if not self.dry_run: os.remove(file) - except OSError, e: + except OSError as e: log.error(str(e)) # Delete the directories. First reverse-sort the normalized paths by # length so that child directories are deleted before their parents. @@ -547,7 +549,7 @@ class my_uninstall(Command): log.info("Removing the directory '%s'." % dir) if not self.dry_run: os.rmdir(dir) - except OSError, e: + except OSError as e: if e.errno == errno.ENOTEMPTY: log.info("Directory '%s' not empty; not removing." % dir) else: diff --git a/zenmap/share/zenmap/locale/xgettext-profile_editor.py b/zenmap/share/zenmap/locale/xgettext-profile_editor.py index 6ac69da..ca0c337 100755 --- a/zenmap/share/zenmap/locale/xgettext-profile_editor.py +++ b/zenmap/share/zenmap/locale/xgettext-profile_editor.py @@ -3,6 +3,7 @@ # This program acts like xgettext, specialized to extract strings from Zenmap's # profile_editor.xml file. +from __future__ import print_function import getopt import os import sys @@ -21,10 +22,10 @@ def escape(s): def output_msgid(msgid, locator): - print - print u"#: %s:%d" % (locator.getSystemId(), locator.getLineNumber()) - print u"msgid", escape(msgid) - print u"msgstr", escape(u"") + print() + print(u"#: %s:%d" % (locator.getSystemId(), locator.getLineNumber())) + print(u"msgid", escape(msgid)) + print(u"msgstr", escape(u"")) class Handler (xml.sax.handler.ContentHandler): diff --git a/zenmap/test/run_tests.py b/zenmap/test/run_tests.py index 993f0bd..c62babd 100644 --- a/zenmap/test/run_tests.py +++ b/zenmap/test/run_tests.py @@ -1,5 +1,6 @@ #!/usr/bin/env python +from __future__ import print_function import unittest if __name__ == "__main__": diff --git a/zenmap/zenmapCore/DelayedObject.py b/zenmap/zenmapCore/DelayedObject.py index f5476c1..c655c34 100644 --- a/zenmap/zenmapCore/DelayedObject.py +++ b/zenmap/zenmapCore/DelayedObject.py @@ -127,6 +127,7 @@ # ***************************************************************************/ +from builtins import object class DelayedObject(object): def __init__(self, klass, *args, **kwargs): object.__setattr__(self, "klass", klass) diff --git a/zenmap/zenmapCore/I18N.py b/zenmap/zenmapCore/I18N.py index d5662ea..835aea1 100644 --- a/zenmap/zenmapCore/I18N.py +++ b/zenmap/zenmapCore/I18N.py @@ -126,6 +126,8 @@ # * * # ***************************************************************************/ +from future import standard_library +standard_library.install_aliases() import locale import os import sys @@ -172,10 +174,10 @@ def install_gettext(locale_dir): else: t = gettext.translation( APP_NAME, locale_dir, languages=get_locales(), fallback=True) - t.install(unicode=True) + t.install(str=True) # Install a dummy _ function so modules can safely use it after importing this # module, even if they don't install the gettext version. -import __builtin__ -__builtin__.__dict__["_"] = lambda s: s +import builtins +builtins.__dict__["_"] = lambda s: s diff --git a/zenmap/zenmapCore/NSEDocParser.py b/zenmap/zenmapCore/NSEDocParser.py index 7edeb19..9673849 100644 --- a/zenmap/zenmapCore/NSEDocParser.py +++ b/zenmap/zenmapCore/NSEDocParser.py @@ -126,6 +126,7 @@ # * * # ***************************************************************************/ +from builtins import object import re diff --git a/zenmap/zenmapCore/NetworkInventory.py b/zenmap/zenmapCore/NetworkInventory.py index 14a4cd7..bfdc087 100644 --- a/zenmap/zenmapCore/NetworkInventory.py +++ b/zenmap/zenmapCore/NetworkInventory.py @@ -126,12 +126,18 @@ # * * # ***************************************************************************/ +from __future__ import print_function +from __future__ import absolute_import +from future import standard_library +standard_library.install_aliases() +from builtins import str +from builtins import object import os import unittest import zenmapCore import zenmapCore.NmapParser from zenmapGUI.SearchGUI import SearchParser -from SearchResult import HostSearch +from .SearchResult import HostSearch class NetworkInventory(object): @@ -186,7 +192,7 @@ class NetworkInventory(object): if filename is not None: basename = os.path.basename(filename) - if basename in self.filenames.values(): + if basename in list(self.filenames.values()): # We need to generate a new filename, since this basename # already exists base = basename @@ -197,7 +203,7 @@ class NetworkInventory(object): pass counter = 2 - while basename in self.filenames.values(): + while basename in list(self.filenames.values()): basename = "%s %s.%s" % (base, counter, ext) counter += 1 @@ -323,13 +329,13 @@ class NetworkInventory(object): return self.scans def get_hosts(self): - return self.hosts.values() + return list(self.hosts.values()) def get_hosts_up(self): - return filter(lambda h: h.get_state() == 'up', self.hosts.values()) + return [h for h in list(self.hosts.values()) if h.get_state() == 'up'] def get_hosts_down(self): - return filter(lambda h: h.get_state() == 'down', self.hosts.values()) + return [h for h in list(self.hosts.values()) if h.get_state() == 'down'] def open_from_file(self, path): """Loads a scan from the given file.""" @@ -370,7 +376,7 @@ class NetworkInventory(object): # The directory must not contain filenames other than those in the # self.filenames dictionary for filename in os.listdir(path): - if os.path.basename(filename) not in self.filenames.values(): + if os.path.basename(filename) not in list(self.filenames.values()): raise Exception("The destination directory contains a file" "(%s) that's not a part of the current inventory." "The inventory will not be saved." % @@ -406,7 +412,7 @@ class NetworkInventory(object): # successfully open a zero-length file. filename_full = filename + ".xml" counter = 2 - while filename_full in self.filenames.values(): + while filename_full in list(self.filenames.values()): # There's already a scan with this filename, so we generate a # new name by appending the counter value before the file # extension. @@ -421,12 +427,12 @@ class NetworkInventory(object): a list of (full-path) filenames that were used to save the scans.""" self._generate_filenames(path) - for scan, filename in self.filenames.iteritems(): + for scan, filename in list(self.filenames.items()): f = open(os.path.join(path, filename), "w") scan.write_xml(f) f.close() - return self.filenames.values() + return list(self.filenames.values()) def open_from_db(self, id): pass @@ -435,7 +441,7 @@ class NetworkInventory(object): # For now, this saves each scan making up the inventory separately in # the database. from time import time - from cStringIO import StringIO + from io import StringIO from zenmapCore.UmitDB import Scans for parsed in self.get_scans(): @@ -492,15 +498,13 @@ class FilteredNetworkInventory(NetworkInventory): def get_hosts_up(self): if len(self.search_dict) > 0: - return filter(lambda h: h.get_state() == 'up', - self.filtered_hosts) + return [h for h in self.filtered_hosts if h.get_state() == 'up'] else: return NetworkInventory.get_hosts_up(self) def get_hosts_down(self): if len(self.search_dict) > 0: - return filter(lambda h: h.get_state() == 'down', - self.filtered_hosts) + return [h for h in self.filtered_hosts if h.get_state() == 'down'] else: return NetworkInventory.get_hosts_down(self) @@ -576,10 +580,10 @@ class FilteredNetworkInventory(NetworkInventory): self.filter_text = filter_text.lower() self.search_parser.update(self.filter_text) self.filtered_hosts = [] - for hostname, host in self.hosts.iteritems(): + for hostname, host in list(self.hosts.items()): # For each host in this scan # Test each given operator against the current host - for operator, args in self.search_dict.iteritems(): + for operator, args in list(self.search_dict.items()): if not self._match_all_args(host, operator, args): # No match => we discard this scan_result break @@ -650,7 +654,7 @@ class NetworkInventoryTest(unittest.TestCase): inv.remove_scan(scan_3) except: pass - self.assertEqual(added_ips, inv.hosts.keys()) + self.assertEqual(added_ips, list(inv.hosts.keys())) self.assertEqual(host_a.hostnames, ["a"]) self.assertEqual(host_b.hostnames, ["b"]) @@ -714,7 +718,7 @@ if __name__ == "__main__": inventory1.add_scan(scan2) for host in inventory1.get_hosts(): - print "%s" % host.ip["addr"], + print("%s" % host.ip["addr"], end=' ') #if len(host.hostnames) > 0: # print "[%s]:" % host.hostnames[0]["hostname"] #else: @@ -728,14 +732,14 @@ if __name__ == "__main__": # print " (%d)" % len(host.trace["hops"]) inventory1.remove_scan(scan2) - print + print() for host in inventory1.get_hosts(): - print "%s" % host.ip["addr"], + print("%s" % host.ip["addr"], end=' ') inventory1.add_scan(scan2) - print + print() for host in inventory1.get_hosts(): - print "%s" % host.ip["addr"], + print("%s" % host.ip["addr"], end=' ') dir = "/home/ndwi/scanz/top01" inventory1.save_to_dir(dir) @@ -743,6 +747,6 @@ if __name__ == "__main__": inventory2 = NetworkInventory() inventory2.open_from_dir(dir) - print + print() for host in inventory2.get_hosts(): - print "%s" % host.ip["addr"], + print("%s" % host.ip["addr"], end=' ') diff --git a/zenmap/zenmapCore/NmapCommand.py b/zenmap/zenmapCore/NmapCommand.py index ad4b930..28ee48a 100644 --- a/zenmap/zenmapCore/NmapCommand.py +++ b/zenmap/zenmapCore/NmapCommand.py @@ -129,6 +129,9 @@ # This file contains the definitions of the NmapCommand class, which represents # and runs an Nmap command line. +from builtins import str +from builtins import range +from builtins import object import codecs import errno import locale @@ -142,7 +145,7 @@ import zenmapCore.I18N from types import StringTypes try: import subprocess -except ImportError, e: +except ImportError as e: raise ImportError(str(e) + ".\n" + _("Python 2.4 or later is required.")) import zenmapCore.Paths @@ -252,7 +255,7 @@ class NmapCommand(object): if self.xml_is_temp: try: os.remove(self.xml_output_filename) - except OSError, e: + except OSError as e: if e.errno != errno.ENOENT: raise diff --git a/zenmap/zenmapCore/NmapOptions.py b/zenmap/zenmapCore/NmapOptions.py index 895cdeb..e2e2e79 100644 --- a/zenmap/zenmapCore/NmapOptions.py +++ b/zenmap/zenmapCore/NmapOptions.py @@ -81,10 +81,13 @@ # get_option_check_auxiliary_widget in OptionBuilder.py. # 7) Make sure the test case works now. +from builtins import str +from past.builtins import basestring +from builtins import object from functools import reduce -class option: +class option(object): """A single option, part of a pool of potential options. It's just a name and a flag saying if the option takes no argument, if an argument is optional, or if an argument is required.""" @@ -640,7 +643,7 @@ class NmapOptions(object): self["-d"] = int(arg) except ValueError: if reduce(lambda x, y: x and y, - map(lambda z: z == "d", arg), True): + [z == "d" for z in arg], True): self.setdefault("-d", 0) self["-d"] += len(arg) + 1 else: @@ -720,7 +723,7 @@ class NmapOptions(object): self["-v"] = -1 except ValueError: if reduce(lambda x, y: x and y, - map(lambda z: z == "v", arg), True): + [z == "v" for z in arg], True): self.setdefault("-v", 0) self["-v"] += len(arg) + 1 else: diff --git a/zenmap/zenmapCore/NmapParser.py b/zenmap/zenmapCore/NmapParser.py index 5368933..4cc5b7f 100644 --- a/zenmap/zenmapCore/NmapParser.py +++ b/zenmap/zenmapCore/NmapParser.py @@ -126,6 +126,13 @@ # * * # ***************************************************************************/ +from __future__ import print_function +from future import standard_library +standard_library.install_aliases() +from builtins import str +from builtins import chr +from builtins import range +from builtins import object import locale import os import os.path @@ -135,9 +142,9 @@ import copy # Use the faster cStringIO if available, fallback on StringIO if not try: - from cStringIO import StringIO + from io import StringIO except ImportError: - from StringIO import StringIO + from io import StringIO # Prevent loading PyXML import xml @@ -1407,25 +1414,25 @@ if __name__ == '__main__': np.parse_file(file_to_parse) for host in np.hosts: - print "%s:" % host.ip["addr"] - print " Comment:", repr(host.comment) - print " TCP sequence:", repr(host.tcpsequence) - print " TCP TS sequence:", repr(host.tcptssequence) - print " IP ID sequence:", repr(host.ipidsequence) - print " Uptime:", repr(host.uptime) - print " OS Match:", repr(host.osmatches) - print " Ports:" + print("%s:" % host.ip["addr"]) + print(" Comment:", repr(host.comment)) + print(" TCP sequence:", repr(host.tcpsequence)) + print(" TCP TS sequence:", repr(host.tcptssequence)) + print(" IP ID sequence:", repr(host.ipidsequence)) + print(" Uptime:", repr(host.uptime)) + print(" OS Match:", repr(host.osmatches)) + print(" Ports:") for p in host.ports: - print "\t%s" % repr(p) - print " Ports used:", repr(host.ports_used) - print " OS Matches:", repr(host.osmatches) - print " Hostnames:", repr(host.hostnames) - print " IP:", repr(host.ip) - print " IPv6:", repr(host.ipv6) - print " MAC:", repr(host.mac) - print " State:", repr(host.state) + print("\t%s" % repr(p)) + print(" Ports used:", repr(host.ports_used)) + print(" OS Matches:", repr(host.osmatches)) + print(" Hostnames:", repr(host.hostnames)) + print(" IP:", repr(host.ip)) + print(" IPv6:", repr(host.ipv6)) + print(" MAC:", repr(host.mac)) + print(" State:", repr(host.state)) if "hops" in host.trace: - print " Trace:" + print(" Trace:") for hop in host.trace["hops"]: - print " ", repr(hop) - print + print(" ", repr(hop)) + print() diff --git a/zenmap/zenmapCore/Paths.py b/zenmap/zenmapCore/Paths.py index 4b7aaeb..6c85da4 100644 --- a/zenmap/zenmapCore/Paths.py +++ b/zenmap/zenmapCore/Paths.py @@ -126,6 +126,8 @@ # * * # ***************************************************************************/ +from __future__ import print_function +from builtins import object from os.path import join, dirname import errno @@ -251,7 +253,7 @@ def create_dir(path): directory already exists.""" try: os.makedirs(path) - except OSError, e: + except OSError as e: if e.errno != errno.EEXIST: raise @@ -293,19 +295,19 @@ def return_if_exists(path, create=False): Path = Paths() if __name__ == '__main__': - print ">>> SAVED DIRECTORIES:" - print ">>> LOCALE DIR:", Path.locale_dir - print ">>> PIXMAPS DIR:", Path.pixmaps_dir - print ">>> CONFIG DIR:", Path.config_dir - print - print ">>> FILES:" - print ">>> USER CONFIG FILE:", Path.user_config_file - print ">>> CONFIG FILE:", Path.user_config_file - print ">>> TARGET_LIST:", Path.target_list - print ">>> PROFILE_EDITOR:", Path.profile_editor - print ">>> SCAN_PROFILE:", Path.scan_profile - print ">>> RECENT_SCANS:", Path.recent_scans - print ">>> OPTIONS:", Path.options - print - print ">>> DB:", Path.db - print ">>> VERSION:", Path.version + print(">>> SAVED DIRECTORIES:") + print(">>> LOCALE DIR:", Path.locale_dir) + print(">>> PIXMAPS DIR:", Path.pixmaps_dir) + print(">>> CONFIG DIR:", Path.config_dir) + print() + print(">>> FILES:") + print(">>> USER CONFIG FILE:", Path.user_config_file) + print(">>> CONFIG FILE:", Path.user_config_file) + print(">>> TARGET_LIST:", Path.target_list) + print(">>> PROFILE_EDITOR:", Path.profile_editor) + print(">>> SCAN_PROFILE:", Path.scan_profile) + print(">>> RECENT_SCANS:", Path.recent_scans) + print(">>> OPTIONS:", Path.options) + print() + print(">>> DB:", Path.db) + print(">>> VERSION:", Path.version) diff --git a/zenmap/zenmapCore/RecentScans.py b/zenmap/zenmapCore/RecentScans.py index 196b3fc..570d7e9 100644 --- a/zenmap/zenmapCore/RecentScans.py +++ b/zenmap/zenmapCore/RecentScans.py @@ -126,6 +126,8 @@ # * * # ***************************************************************************/ +from __future__ import print_function +from builtins import object from os import access, R_OK, W_OK from os.path import dirname from zenmapCore.Paths import Path @@ -183,7 +185,7 @@ if __name__ == "__main__": import sys from os.path import split r = RecentScans() - print ">>> Getting empty list:", r.get_recent_scans_list() - print ">>> Adding recent scan bla:", r.add_recent_scan("bla") - print ">>> Getting recent scan list:", r.get_recent_scans_list() + print(">>> Getting empty list:", r.get_recent_scans_list()) + print(">>> Adding recent scan bla:", r.add_recent_scan("bla")) + print(">>> Getting recent scan list:", r.get_recent_scans_list()) del r diff --git a/zenmap/zenmapCore/ScriptArgsParser.py b/zenmap/zenmapCore/ScriptArgsParser.py index 10aad24..2b0d46e 100644 --- a/zenmap/zenmapCore/ScriptArgsParser.py +++ b/zenmap/zenmapCore/ScriptArgsParser.py @@ -129,6 +129,7 @@ # pairs. The logic is same as in nse_main.lua, except that values are not # returned as tables but as strings. +from __future__ import print_function import re # "^%s*([^'\"%s{},=][^{},=]-)%s*[},=]" unquoted_re = re.compile(r'\s*([^\'"\s{},=][^{},=]*?)\s*([},=]|$)') @@ -256,21 +257,21 @@ if __name__ == '__main__': for test, expected in TESTS: args_dict = parse_script_args_dict(test) - print args_dict + print(args_dict) args = parse_script_args(test) if args == expected: - print "PASS", test + print("PASS", test) continue - print "FAIL", test + print("FAIL", test) if args is None: - print "Parsing error" + print("Parsing error") else: - print "%d args" % len(args) + print("%d args" % len(args)) for a, v in args: - print a, "=", v + print(a, "=", v) if expected is None: - print "Expected parsing error" + print("Expected parsing error") else: - print "Expected %d args" % len(expected) + print("Expected %d args" % len(expected)) for a, v in expected: - print a, "=", v + print(a, "=", v) diff --git a/zenmap/zenmapCore/ScriptMetadata.py b/zenmap/zenmapCore/ScriptMetadata.py index bf0678b..dfa24a1 100644 --- a/zenmap/zenmapCore/ScriptMetadata.py +++ b/zenmap/zenmapCore/ScriptMetadata.py @@ -130,6 +130,9 @@ # ScriptMetadata gets the description, categories, @usage, @output, and # arguments from the script itself. +from __future__ import print_function +from builtins import chr +from builtins import object import re import os import sys @@ -521,16 +524,16 @@ def get_script_entries(scripts_dir, nselib_dir): if __name__ == '__main__': import sys for entry in get_script_entries(sys.argv[1], sys.argv[2]): - print "*" * 75 - print "Filename:", entry.filename - print "Categories:", entry.categories - print "License:", entry.license - print "Author:", entry.author - print "URL:", entry.url - print "Description:", entry.description - print "Arguments:", [x[0] for x in entry.arguments] - print "Output:" - print entry.output - print "Usage:" - print entry.usage - print "*" * 75 + print("*" * 75) + print("Filename:", entry.filename) + print("Categories:", entry.categories) + print("License:", entry.license) + print("Author:", entry.author) + print("URL:", entry.url) + print("Description:", entry.description) + print("Arguments:", [x[0] for x in entry.arguments]) + print("Output:") + print(entry.output) + print("Usage:") + print(entry.usage) + print("*" * 75) diff --git a/zenmap/zenmapCore/SearchResult.py b/zenmap/zenmapCore/SearchResult.py index cdb1029..3658dd0 100644 --- a/zenmap/zenmapCore/SearchResult.py +++ b/zenmap/zenmapCore/SearchResult.py @@ -126,10 +126,15 @@ # * * # ***************************************************************************/ +from future import standard_library +standard_library.install_aliases() +from builtins import str +from builtins import range +from builtins import object import os import os.path import re -import StringIO +import io import unittest from glob import glob @@ -238,7 +243,7 @@ class SearchResult(object): self.parsed_scan = scan_result # Test each given operator against the current parsed result - for operator, args in kargs.iteritems(): + for operator, args in list(kargs.items()): if not self._match_all_args(operator, args): # No match => we discard this scan_result break @@ -392,7 +397,7 @@ class SearchResult(object): return True # Transform a comma-delimited string containing ports into a list - ports = filter(lambda not_empty: not_empty, ports.split(",")) + ports = [not_empty for not_empty in ports.split(",") if not_empty] # Check if they're parsable, if not return False silently for port in ports: @@ -429,7 +434,7 @@ class SearchResult(object): log.debug("Match port:%s" % ports) # Transform a comma-delimited string containing ports into a list - ports = filter(lambda not_empty: not_empty, ports.split(",")) + ports = [not_empty for not_empty in ports.split(",") if not_empty] for host in self.parsed_scan.get_hosts(): for port in ports: @@ -520,11 +525,11 @@ class SearchDB(SearchResult, object): log.debug(">>> Nmap xml output: %s" % scan.nmap_xml_output) try: - buffer = StringIO.StringIO(scan.nmap_xml_output) + buffer = io.StringIO(scan.nmap_xml_output) parsed = NmapParser() parsed.parse(buffer) buffer.close() - except Exception, e: + except Exception as e: log.warning(">>> Error loading scan with ID %u from database: " "%s" % (scan.scans_id, str(e))) else: diff --git a/zenmap/zenmapCore/TargetList.py b/zenmap/zenmapCore/TargetList.py index 836c486..405f82b 100644 --- a/zenmap/zenmapCore/TargetList.py +++ b/zenmap/zenmapCore/TargetList.py @@ -126,6 +126,8 @@ # * * # ***************************************************************************/ +from __future__ import print_function +from builtins import object from os import access, R_OK, W_OK from os.path import dirname from zenmapCore.Paths import Path @@ -184,7 +186,7 @@ if __name__ == "__main__": import sys from os.path import split t = TargetList() - print ">>> Getting empty list:", t.get_target_list() - print ">>> Adding target 127.0.0.1:", t.add_target("127.0.0.3") - print ">>> Getting target list:", t.get_target_list() + print(">>> Getting empty list:", t.get_target_list()) + print(">>> Adding target 127.0.0.1:", t.add_target("127.0.0.3")) + print(">>> Getting target list:", t.get_target_list()) del t diff --git a/zenmap/zenmapCore/UmitConf.py b/zenmap/zenmapCore/UmitConf.py index 12fc39e..f4bf217 100644 --- a/zenmap/zenmapCore/UmitConf.py +++ b/zenmap/zenmapCore/UmitConf.py @@ -126,11 +126,17 @@ # * * # ***************************************************************************/ +from future import standard_library +standard_library.install_aliases() +from builtins import str +from builtins import range +from past.builtins import basestring +from builtins import object import re from types import StringTypes -from ConfigParser import DuplicateSectionError, NoSectionError, NoOptionError -from ConfigParser import Error as ConfigParser_Error +from configparser import DuplicateSectionError, NoSectionError, NoOptionError +from configparser import Error as ConfigParser_Error from zenmapCore.Paths import Path from zenmapCore.UmitLogging import log @@ -483,7 +489,7 @@ class NmapOutputHighlight(object): property_name = "%s_highlight" % property_name settings = self.sanity_settings(list(settings)) - for pos in xrange(len(settings)): + for pos in range(len(settings)): config_parser.set(property_name, self.setts[pos], settings[pos]) def sanity_settings(self, settings): @@ -696,7 +702,7 @@ class PathsConfig(object): # Exceptions -class ProfileNotFound: +class ProfileNotFound(object): def __init__(self, profile): self.profile = profile @@ -704,7 +710,7 @@ class ProfileNotFound: return "No profile named '" + self.profile + "' found!" -class ProfileCouldNotBeSaved: +class ProfileCouldNotBeSaved(object): def __init__(self, profile): self.profile = profile diff --git a/zenmap/zenmapCore/UmitConfigParser.py b/zenmap/zenmapCore/UmitConfigParser.py index 51605b3..3113617 100644 --- a/zenmap/zenmapCore/UmitConfigParser.py +++ b/zenmap/zenmapCore/UmitConfigParser.py @@ -126,8 +126,11 @@ # * * # ***************************************************************************/ +from future import standard_library +standard_library.install_aliases() +from builtins import str from os.path import exists -from ConfigParser import ConfigParser, DEFAULTSECT, NoOptionError, \ +from configparser import ConfigParser, DEFAULTSECT, NoOptionError, \ NoSectionError from zenmapCore.UmitLogging import log @@ -173,19 +176,19 @@ class UmitConfigParser(ConfigParser): if self._defaults: fp.write("[%s]\n" % DEFAULTSECT) - items = self._defaults.items() + items = list(self._defaults.items()) items.sort() for (key, value) in items: fp.write("%s = %s\n" % (key, str(value).replace('\n', '\n\t'))) fp.write("\n") - sects = self._sections.keys() + sects = list(self._sections.keys()) sects.sort() for section in sects: fp.write("[%s]\n" % section) - for (key, value) in self._sections[section].items(): + for (key, value) in list(self._sections[section].items()): if key != "__name__": fp.write("%s = %s\n" % (key, str(value).replace('\n', '\n\t'))) diff --git a/zenmap/zenmapCore/UmitDB.py b/zenmap/zenmapCore/UmitDB.py index 75c4eda..fc8bf29 100644 --- a/zenmap/zenmapCore/UmitDB.py +++ b/zenmap/zenmapCore/UmitDB.py @@ -126,6 +126,10 @@ # * * # ***************************************************************************/ +from __future__ import print_function +from __future__ import absolute_import +from builtins import range +from builtins import object import sys try: @@ -157,7 +161,7 @@ try: umitdb = Path.db except: import os.path - from BasePaths import base_paths + from .BasePaths import base_paths umitdb = os.path.join(Path.user_config_dir, base_paths["db"]) Path.db = umitdb @@ -236,14 +240,14 @@ class Table(object): def insert(self, **kargs): sql = "INSERT INTO %s (" - for k in kargs.keys(): + for k in list(kargs.keys()): sql += k sql += ", " else: sql = sql[:][:-2] sql += ") VALUES (" - for v in xrange(len(kargs.values())): + for v in range(len(list(kargs.values()))): sql += "?, " else: sql = sql[:][:-2] @@ -314,19 +318,19 @@ class UmitDB(object): class Scans(Table, object): def __init__(self, **kargs): Table.__init__(self, "scans") - if "scans_id" in kargs.keys(): + if "scans_id" in list(kargs.keys()): self.scans_id = kargs["scans_id"] else: log.debug(">>> Creating new scan result entry at data base") fields = ["scan_name", "nmap_xml_output", "date"] - for k in kargs.keys(): + for k in list(kargs.keys()): if k not in fields: raise Exception( "Wrong table field passed to creation method. " "'%s'" % k) - if ("nmap_xml_output" not in kargs.keys() or + if ("nmap_xml_output" not in list(kargs.keys()) or not kargs["nmap_xml_output"]): raise Exception("Can't save result without xml output") @@ -427,5 +431,5 @@ if __name__ == "__main__": sql = "SELECT * FROM scans;" u.cursor.execute(sql) - print "Scans:", + print("Scans:", end=' ') pprint(u.cursor.fetchall()) diff --git a/zenmap/zenmapGUI/App.py b/zenmap/zenmapGUI/App.py index 64b514a..89275e1 100644 --- a/zenmap/zenmapGUI/App.py +++ b/zenmap/zenmapGUI/App.py @@ -126,11 +126,14 @@ # * * # ***************************************************************************/ +from future import standard_library +standard_library.install_aliases() +from builtins import str import imp import os import signal import sys -import ConfigParser +import configparser import shutil # Cause an exception if PyGTK can't open a display. Normally this just @@ -183,7 +186,7 @@ def _destroy_callback(window): gtk.main_quit() try: from zenmapCore.UmitDB import UmitDB - except ImportError, e: + except ImportError as e: log.debug(">>> Not cleaning up database: %s." % str(e)) else: # Cleaning up data base @@ -243,7 +246,7 @@ def install_excepthook(): message_format=_("Import error"), secondary_text=_("""A required module was not found. -""" + unicode(value))) +""" + str(value))) d.run() d.destroy() else: @@ -286,7 +289,7 @@ def run(): # template directory. zenmapCore.Paths.create_user_config_dir( Path.user_config_dir, Path.config_dir) - except (IOError, OSError), e: + except (IOError, OSError) as e: error_dialog = HIGAlertDialog( message_format=_( "Error creating the per-user configuration directory"), @@ -310,7 +313,7 @@ scan profiles. Check for access to the directory and try again.""") % ( try: # Read the ~/.zenmap/zenmap.conf configuration file. zenmapCore.UmitConf.config_parser.read(Path.user_config_file) - except ConfigParser.ParsingError, e: + except configparser.ParsingError as e: # ParsingError can leave some values as lists instead of strings. Just # blow it all away if we have this problem. zenmapCore.UmitConf.config_parser = zenmapCore.UmitConf.config_parser.__class__() diff --git a/zenmap/zenmapGUI/DiffCompare.py b/zenmap/zenmapGUI/DiffCompare.py index 2bcc138..c3e188c 100644 --- a/zenmap/zenmapGUI/DiffCompare.py +++ b/zenmap/zenmapGUI/DiffCompare.py @@ -126,6 +126,7 @@ # * * # ***************************************************************************/ +from builtins import str import gobject import gtk import pango @@ -288,7 +289,7 @@ class ScanChooser(HIGVBox): def add_scan(self, scan_name, parser): scan_id = 1 new_scan_name = scan_name - while new_scan_name in self.scan_dict.keys(): + while new_scan_name in list(self.scan_dict.keys()): new_scan_name = "%s (%s)" % (scan_name, scan_id) scan_id += 1 diff --git a/zenmap/zenmapGUI/MainWindow.py b/zenmap/zenmapGUI/MainWindow.py index 27c33b1..40b5c02 100644 --- a/zenmap/zenmapGUI/MainWindow.py +++ b/zenmap/zenmapGUI/MainWindow.py @@ -126,6 +126,9 @@ # * * # ***************************************************************************/ +from future import standard_library +standard_library.install_aliases() +from builtins import str import gtk import sys @@ -481,7 +484,7 @@ class ScanWindow(UmitScanWindow): log.debug(">>> Saving result into database...") try: scan_interface.inventory.save_to_db() - except Exception, e: + except Exception as e: alert = HIGAlertDialog( message_format=_("Can't save to database"), secondary_text=_("Can't store unsaved scans to the " @@ -608,7 +611,7 @@ class ScanWindow(UmitScanWindow): try: # Parse result scan_interface.load_from_file(filename) - except Exception, e: + except Exception as e: alert = HIGAlertDialog(message_format=_('Error loading file'), secondary_text=str(e)) alert.run() @@ -758,7 +761,7 @@ This scan has not been run yet. Start the scan with the "Scan" button first.')) filenames = scan_interface.inventory.save_to_dir(directory) for scan in scan_interface.inventory.get_scans(): scan.unsaved = False - except Exception, ex: + except Exception as ex: alert = HIGAlertDialog(message_format=_('Can\'t save file'), secondary_text=str(ex)) alert.run() @@ -780,7 +783,7 @@ This scan has not been run yet. Start the scan with the "Scan" button first.')) scan_interface.inventory.save_to_file( saved_filename, selected_index, format) scan_interface.inventory.get_scans()[selected_index].unsaved = False # noqa - except (OSError, IOError), e: + except (OSError, IOError) as e: alert = HIGAlertDialog( message_format=_("Can't save file"), secondary_text=_("Can't open file to write.\n%s") % str(e)) @@ -956,7 +959,7 @@ This scan has not been run yet. Start the scan with the "Scan" button first.')) def show_help(): - import urllib + import urllib.request, urllib.parse, urllib.error import webbrowser new = 0 @@ -964,16 +967,16 @@ def show_help(): new = 2 doc_path = abspath(join(Path.docs_dir, "help.html")) - url = "file:" + urllib.pathname2url(fs_enc(doc_path)) + url = "file:" + urllib.request.pathname2url(fs_enc(doc_path)) try: webbrowser.open(url, new=new) - except OSError, e: + except OSError as e: d = HIGAlertDialog(parent=self, message_format=_("Can't find documentation files"), secondary_text=_("""\ There was an error loading the documentation file %s (%s). See the \ online documentation at %s.\ -""") % (doc_path, unicode(e), APP_DOCUMENTATION_SITE)) +""") % (doc_path, str(e), APP_DOCUMENTATION_SITE)) d.run() d.destroy() diff --git a/zenmap/zenmapGUI/NmapOutputProperties.py b/zenmap/zenmapGUI/NmapOutputProperties.py index 3cc2e8f..a59f173 100644 --- a/zenmap/zenmapGUI/NmapOutputProperties.py +++ b/zenmap/zenmapGUI/NmapOutputProperties.py @@ -126,6 +126,7 @@ # * * # ***************************************************************************/ +from builtins import object import gtk import gtk.gdk import pango diff --git a/zenmap/zenmapGUI/OptionBuilder.py b/zenmap/zenmapGUI/OptionBuilder.py index ca55f37..328f18a 100644 --- a/zenmap/zenmapGUI/OptionBuilder.py +++ b/zenmap/zenmapGUI/OptionBuilder.py @@ -126,6 +126,8 @@ # * * # ***************************************************************************/ +from builtins import str +from builtins import object import gobject import gtk @@ -340,7 +342,7 @@ class OptionTab(object): self.widgets_list = [] for option_element in root_tab.childNodes: if (hasattr(option_element, "tagName") and - option_element.tagName in actions.keys()): + option_element.tagName in list(actions.keys())): parse_func = actions[option_element.tagName] widget = parse_func(option_element) self.widgets_list.append(widget) @@ -492,7 +494,7 @@ class OptionBuilder(object): self.tabs = self.__parse_tabs() def update(self): - for tab in self.tabs.values(): + for tab in list(self.tabs.values()): tab.update() def __parse_section_names(self): diff --git a/zenmap/zenmapGUI/Print.py b/zenmap/zenmapGUI/Print.py index b37a980..8343785 100644 --- a/zenmap/zenmapGUI/Print.py +++ b/zenmap/zenmapGUI/Print.py @@ -139,6 +139,9 @@ # Add options to the print dialog to control the font, coloring, and anything # else. This might go in a separate Print Setup dialog. +from __future__ import division +from builtins import object +from past.utils import old_div import gtk import gobject import pango @@ -169,11 +172,11 @@ class PrintState (object): layout.set_text("dummy") line = layout.get_line(0) # get_extents()[1][3] is the height of the logical rectangle. - line_height = line.get_extents()[1][3] / float(pango.SCALE) + line_height = old_div(line.get_extents()[1][3], float(pango.SCALE)) page_height = context.get_height() - self.lines_per_page = int(page_height / line_height) - op.set_n_pages((len(self.lines) - 1) / self.lines_per_page + 1) + self.lines_per_page = int(old_div(page_height, line_height)) + op.set_n_pages(old_div((len(self.lines) - 1), self.lines_per_page) + 1) def draw_page(self, op, context, page_nr): this_page_lines = self.lines[ diff --git a/zenmap/zenmapGUI/ProfileCombo.py b/zenmap/zenmapGUI/ProfileCombo.py index f04e9d9..0bad231 100644 --- a/zenmap/zenmapGUI/ProfileCombo.py +++ b/zenmap/zenmapGUI/ProfileCombo.py @@ -126,6 +126,7 @@ # * * # ***************************************************************************/ +from builtins import range import gtk from zenmapCore.UmitConf import CommandProfile diff --git a/zenmap/zenmapGUI/ProfileEditor.py b/zenmap/zenmapGUI/ProfileEditor.py index 9a84f3b..38484d0 100644 --- a/zenmap/zenmapGUI/ProfileEditor.py +++ b/zenmap/zenmapGUI/ProfileEditor.py @@ -126,6 +126,7 @@ # * * # ***************************************************************************/ +from builtins import str import gtk from zenmapGUI.higwidgets.higwindows import HIGWindow diff --git a/zenmap/zenmapGUI/ProfileHelp.py b/zenmap/zenmapGUI/ProfileHelp.py index 2cf236f..b244c56 100644 --- a/zenmap/zenmapGUI/ProfileHelp.py +++ b/zenmap/zenmapGUI/ProfileHelp.py @@ -126,10 +126,11 @@ # * * # ***************************************************************************/ +from builtins import object from zenmapCore.UmitLogging import log -class ProfileHelp: +class ProfileHelp(object): def __init__(self, currentstate=None): self.currentstate = "Default" self.labels = {} diff --git a/zenmap/zenmapGUI/ScanHostDetailsPage.py b/zenmap/zenmapGUI/ScanHostDetailsPage.py index b2df892..b24018b 100644 --- a/zenmap/zenmapGUI/ScanHostDetailsPage.py +++ b/zenmap/zenmapGUI/ScanHostDetailsPage.py @@ -126,6 +126,9 @@ # * * # ***************************************************************************/ +from __future__ import division +from builtins import str +from past.utils import old_div import gtk from zenmapGUI.higwidgets.higexpanders import HIGExpander @@ -377,7 +380,7 @@ class HostDetails(HIGVBox): progress = gtk.ProgressBar() if 'accuracy' in os: - progress.set_fraction(float(os['accuracy']) / 100.0) + progress.set_fraction(old_div(float(os['accuracy']), 100.0)) progress.set_text(os['accuracy'] + '%') else: progress.set_text(_('Not Available')) @@ -445,7 +448,7 @@ class HostDetails(HIGVBox): progress = gtk.ProgressBar() progress.set_text(o['accuracy'] + '%') - progress.set_fraction(float(o['accuracy']) / 100.0) + progress.set_fraction(old_div(float(o['accuracy']), 100.0)) table.attach(progress, 4, 5, y1, y2) y1 += 1 y2 += 1 diff --git a/zenmap/zenmapGUI/ScanHostsView.py b/zenmap/zenmapGUI/ScanHostsView.py index 69e6ed2..5ff1163 100644 --- a/zenmap/zenmapGUI/ScanHostsView.py +++ b/zenmap/zenmapGUI/ScanHostsView.py @@ -126,6 +126,8 @@ # * * # ***************************************************************************/ +from past.builtins import cmp +from builtins import range import gtk from types import StringTypes @@ -147,7 +149,7 @@ def cmp_treemodel_addr(model, iter_a, iter_b): class ScanHostsView(HIGVBox, object): - HOST_MODE, SERVICE_MODE = range(2) + HOST_MODE, SERVICE_MODE = list(range(2)) def __init__(self, scan_interface): HIGVBox.__init__(self) diff --git a/zenmap/zenmapGUI/ScanInterface.py b/zenmap/zenmapGUI/ScanInterface.py index 4698988..f8b3cce 100644 --- a/zenmap/zenmapGUI/ScanInterface.py +++ b/zenmap/zenmapGUI/ScanInterface.py @@ -126,6 +126,7 @@ # * * # ***************************************************************************/ +from builtins import str import errno import gtk import gobject @@ -437,7 +438,7 @@ class ScanInterface(HIGVBox): if target != '': try: self.toolbar.add_new_target(target) - except IOError, e: + except IOError as e: # We failed to save target_list.txt; treat it as read-only. # Probably it's owned by root and this is a normal user. log.debug(">>> Error saving %s: %s" % ( @@ -537,7 +538,7 @@ class ScanInterface(HIGVBox): completion.""" try: command_execution = NmapCommand(command) - except IOError, e: + except IOError as e: warn_dialog = HIGAlertDialog( message_format=_("Error building command"), secondary_text=_("Error message: %s") % str(e), @@ -549,7 +550,7 @@ class ScanInterface(HIGVBox): try: command_execution.run_scan() - except Exception, e: + except Exception as e: text = str(e) if isinstance(e, OSError): # Handle ENOENT specially. @@ -631,12 +632,12 @@ class ScanInterface(HIGVBox): parsed = NmapParser() try: parsed.parse_file(command.get_xml_output_filename()) - except IOError, e: + except IOError as e: # It's possible to run Nmap without generating an XML output file, # like with "nmap -V". if e.errno != errno.ENOENT: raise - except xml.sax.SAXParseException, e: + except xml.sax.SAXParseException as e: try: # Some options like --iflist cause Nmap to emit an empty XML # file. Ignore the exception in this case. @@ -658,7 +659,7 @@ class ScanInterface(HIGVBox): self.scan_result.refresh_nmap_output() try: self.inventory.add_scan(parsed) - except Exception, e: + except Exception as e: warn_dialog = HIGAlertDialog( message_format=_("Cannot merge scan"), secondary_text=_( @@ -733,7 +734,7 @@ class ScanInterface(HIGVBox): name = service["service_name"] state = service["port_state"] - if name not in self.services.keys(): + if name not in list(self.services.keys()): self.services[name] = [] hs = {"host": host, "hostname": hostname} diff --git a/zenmap/zenmapGUI/ScanNmapOutputPage.py b/zenmap/zenmapGUI/ScanNmapOutputPage.py index 828935f..805d4ce 100644 --- a/zenmap/zenmapGUI/ScanNmapOutputPage.py +++ b/zenmap/zenmapGUI/ScanNmapOutputPage.py @@ -126,6 +126,7 @@ # * * # ***************************************************************************/ +from builtins import str import gtk import gobject import pango @@ -166,7 +167,7 @@ class Throbber(gtk.Image): os.path.join(Path.pixmaps_dir, "throbber.png")) anim = gtk.gdk.PixbufAnimation( os.path.join(Path.pixmaps_dir, "throbber.gif")) - except Exception, e: + except Exception as e: log.debug("Error loading throbber images: %s." % str(e)) still = None anim = None diff --git a/zenmap/zenmapGUI/ScanOpenPortsPage.py b/zenmap/zenmapGUI/ScanOpenPortsPage.py index ccc3623..d889ecb 100644 --- a/zenmap/zenmapGUI/ScanOpenPortsPage.py +++ b/zenmap/zenmapGUI/ScanOpenPortsPage.py @@ -126,6 +126,8 @@ # * * # ***************************************************************************/ +from past.builtins import cmp +from builtins import range import gtk from zenmapGUI.higwidgets.higboxes import HIGVBox, HIGHBox diff --git a/zenmap/zenmapGUI/ScanRunDetailsPage.py b/zenmap/zenmapGUI/ScanRunDetailsPage.py index 277a26a..08bc87b 100644 --- a/zenmap/zenmapGUI/ScanRunDetailsPage.py +++ b/zenmap/zenmapGUI/ScanRunDetailsPage.py @@ -126,6 +126,7 @@ # * * # ***************************************************************************/ +from builtins import str import gtk from zenmapGUI.higwidgets.higboxes import HIGVBox, HIGHBox,\ hig_box_space_holder diff --git a/zenmap/zenmapGUI/ScansListStore.py b/zenmap/zenmapGUI/ScansListStore.py index 41189b4..18c1d80 100644 --- a/zenmap/zenmapGUI/ScansListStore.py +++ b/zenmap/zenmapGUI/ScansListStore.py @@ -126,6 +126,8 @@ # * * # ***************************************************************************/ +from builtins import range +from builtins import object import gtk @@ -134,7 +136,7 @@ class ScansListStoreEntry(object): otherwise represented by very different classes.""" # Possible states for the scan to be in. - UNINITIALIZED, RUNNING, FINISHED, FAILED, CANCELED = range(5) + UNINITIALIZED, RUNNING, FINISHED, FAILED, CANCELED = list(range(5)) def __init__(self): self.state = self.UNINITIALIZED diff --git a/zenmap/zenmapGUI/ScriptInterface.py b/zenmap/zenmapGUI/ScriptInterface.py index 9bebeea..853cb88 100644 --- a/zenmap/zenmapGUI/ScriptInterface.py +++ b/zenmap/zenmapGUI/ScriptInterface.py @@ -127,6 +127,8 @@ # This module is responsible for interface present under "Scripting" tab. +from builtins import str +from builtins import object import gobject import gtk import sys @@ -227,7 +229,7 @@ class ScriptHelpXMLContentHandler (xml.sax.handler.ContentHandler): return handler -class ScriptInterface: +class ScriptInterface(object): # Timeout, in milliseconds, after the user stops typing and we update the # interface from --script. SCRIPT_LIST_DELAY = 500 @@ -303,7 +305,7 @@ class ScriptInterface: nmap_process = NmapCommand(command_string) try: nmap_process.run_scan(stderr=stderr) - except Exception, e: + except Exception as e: callback(False, None) stderr.close() return @@ -350,7 +352,7 @@ class ScriptInterface: try: handler = ScriptHelpXMLContentHandler.parse_nmap_script_help( process.stdout_file) - except (ValueError, xml.sax.SAXParseException), e: + except (ValueError, xml.sax.SAXParseException) as e: log.debug("--script-help parse exception: %s" % str(e)) return False @@ -411,7 +413,7 @@ class ScriptInterface: try: handler = ScriptHelpXMLContentHandler.parse_nmap_script_help( process.stdout_file) - except (ValueError, xml.sax.SAXParseException), e: + except (ValueError, xml.sax.SAXParseException) as e: log.debug("--script-help parse exception: %s" % str(e)) return False @@ -461,7 +463,7 @@ class ScriptInterface: if arg_dict is None: # if there is parsing error args_dict holds none self.arg_values.clear() else: - for key in arg_dict.keys(): + for key in list(arg_dict.keys()): self.arg_values[key] = arg_dict[key] def update_argument_values(self, raw_argument): @@ -667,7 +669,7 @@ clicking in the value field beside the argument name.""") def update_arg_values(self): """When the widget is updated with argument value, correspondingly update the command line.""" - for key in self.arg_values.keys(): + for key in list(self.arg_values.keys()): if len(self.arg_values[key]) == 0: del self.arg_values[key] else: diff --git a/zenmap/zenmapGUI/SearchGUI.py b/zenmap/zenmapGUI/SearchGUI.py index b937118..82e3ebe 100644 --- a/zenmap/zenmapGUI/SearchGUI.py +++ b/zenmap/zenmapGUI/SearchGUI.py @@ -126,6 +126,9 @@ # * * # ***************************************************************************/ +from builtins import str +from builtins import range +from builtins import object import gtk import os.path import re @@ -248,7 +251,7 @@ class SearchGUI(gtk.VBox, object): if self.options["search_db"]: try: self.search_db = SearchDB() - except ImportError, e: + except ImportError as e: self.search_db = SearchDummy() self.no_db_warning.show() self.no_db_warning.set_text( @@ -416,7 +419,7 @@ class SearchGUI(gtk.VBox, object): # We compare the search entry field to the Expressions GUI. Every # (operator, value) pair must be present in the GUI after this loop # is done. - for op, args in self.search_dict.iteritems(): + for op, args in list(self.search_dict.items()): for arg in args: if (op not in gui_ops) or (arg not in gui_ops[op]): # We need to add this pair to the GUI @@ -511,7 +514,7 @@ class SearchGUI(gtk.VBox, object): self.append_result(result) matched += 1 - for search_dir in self.search_dirs.itervalues(): + for search_dir in list(self.search_dirs.values()): total += len(search_dir.get_scan_results()) for result in search_dir.search(**self.search_dict): self.append_result(result) @@ -628,13 +631,13 @@ class Criterion(gtk.HBox): # Sort all the keys from combo_entries and make an entry for each of # them - sorted_entries = self.combo_entries.keys() + sorted_entries = list(self.combo_entries.keys()) sorted_entries.sort() for name in sorted_entries: self.operator_combo.append_text(name) # Select the default operator - for entry, operators in self.combo_entries.iteritems(): + for entry, operators in list(self.combo_entries.items()): for operator in operators: if operator == self.default_operator: self.operator_combo.set_active(sorted_entries.index(entry)) diff --git a/zenmap/zenmapGUI/TargetCombo.py b/zenmap/zenmapGUI/TargetCombo.py index 45afb4e..991c448 100644 --- a/zenmap/zenmapGUI/TargetCombo.py +++ b/zenmap/zenmapGUI/TargetCombo.py @@ -126,6 +126,7 @@ # * * # ***************************************************************************/ +from builtins import range import gtk from zenmapCore.TargetList import target_list diff --git a/zenmap/zenmapGUI/higwidgets/__init__.py b/zenmap/zenmapGUI/higwidgets/__init__.py index 9758bdf..2c94955 100644 --- a/zenmap/zenmapGUI/higwidgets/__init__.py +++ b/zenmap/zenmapGUI/higwidgets/__init__.py @@ -135,18 +135,19 @@ GNOME Human Interface Guidelines (aka HIG). This is mostly implemented by subclassing from the GTK classes, and providing defaults that better match the HIG specifications/recommendations. """ +from __future__ import absolute_import -from gtkutils import * -from higboxes import * -from higbuttons import * -from higdialogs import * -from higentries import * -from higexpanders import * -from higlabels import * -from higlogindialogs import * -from higprogressbars import * -from higscrollers import * -from higspinner import * -from higtables import * -from higtextviewers import * -from higwindows import * +from .gtkutils import * +from .higboxes import * +from .higbuttons import * +from .higdialogs import * +from .higentries import * +from .higexpanders import * +from .higlabels import * +from .higlogindialogs import * +from .higprogressbars import * +from .higscrollers import * +from .higspinner import * +from .higtables import * +from .higtextviewers import * +from .higwindows import * diff --git a/zenmap/zenmapGUI/higwidgets/higdialogs.py b/zenmap/zenmapGUI/higwidgets/higdialogs.py index a68a9fb..e302868 100644 --- a/zenmap/zenmapGUI/higwidgets/higdialogs.py +++ b/zenmap/zenmapGUI/higwidgets/higdialogs.py @@ -131,12 +131,13 @@ higwidgets/higdialogs.py dialog related classes """ +from __future__ import absolute_import __all__ = ['HIGDialog', 'HIGAlertDialog'] import gtk -from gtkutils import gtk_version_minor +from .gtkutils import gtk_version_minor class HIGDialog(gtk.Dialog): @@ -186,7 +187,7 @@ class HIGAlertDialog(gtk.MessageDialog): if __name__ == '__main__': - from higlabels import HIGEntryLabel, HIGDialogLabel + from .higlabels import HIGEntryLabel, HIGDialogLabel # HIGDialog d = HIGDialog(title='HIGDialog', diff --git a/zenmap/zenmapGUI/higwidgets/higexpanders.py b/zenmap/zenmapGUI/higwidgets/higexpanders.py index 9feba6d..836b4e2 100644 --- a/zenmap/zenmapGUI/higwidgets/higexpanders.py +++ b/zenmap/zenmapGUI/higwidgets/higexpanders.py @@ -131,12 +131,13 @@ higwidgets/higexpanders.py expanders related classes """ +from __future__ import absolute_import __all__ = ['HIGExpander'] import gtk -from higboxes import HIGHBox, hig_box_space_holder +from .higboxes import HIGHBox, hig_box_space_holder class HIGExpander(gtk.Expander): diff --git a/zenmap/zenmapGUI/higwidgets/higframe.py b/zenmap/zenmapGUI/higwidgets/higframe.py index 9fa5432..aad9d96 100644 --- a/zenmap/zenmapGUI/higwidgets/higframe.py +++ b/zenmap/zenmapGUI/higwidgets/higframe.py @@ -132,6 +132,7 @@ higwidgets/higframe.py hig frame """ +from builtins import range __all__ = ['HIGFrame'] import gtk @@ -164,7 +165,7 @@ if __name__ == "__main__": hframe.add(aalign) w.add(hframe) - for i in xrange(5): + for i in range(5): abox.pack_start(gtk.Label("Sample %d" % i), False, False, 3) w.connect('destroy', lambda d: gtk.main_quit()) diff --git a/zenmap/zenmapGUI/higwidgets/higlogindialogs.py b/zenmap/zenmapGUI/higwidgets/higlogindialogs.py index c20ba77..c07df02 100644 --- a/zenmap/zenmapGUI/higwidgets/higlogindialogs.py +++ b/zenmap/zenmapGUI/higwidgets/higlogindialogs.py @@ -131,15 +131,17 @@ higwidgets/higlogindialog.py a basic login/authentication dialog """ +from __future__ import print_function +from __future__ import absolute_import __all__ = ['HIGLoginDialog'] import gtk -from higdialogs import HIGDialog -from higlabels import HIGEntryLabel -from higtables import HIGTable -from higentries import HIGTextEntry, HIGPasswordEntry +from .higdialogs import HIGDialog +from .higlabels import HIGEntryLabel +from .higtables import HIGTable +from .higentries import HIGTextEntry, HIGPasswordEntry class HIGLoginDialog(HIGDialog): @@ -175,10 +177,10 @@ class HIGLoginDialog(HIGDialog): if __name__ == '__main__': - from gtkutils import gtk_constant_name + from .gtkutils import gtk_constant_name # HIGLoginDialog d = HIGLoginDialog() response_value = d.run() - print gtk_constant_name('response', response_value) + print(gtk_constant_name('response', response_value)) d.destroy() diff --git a/zenmap/zenmapGUI/higwidgets/hignotebooks.py b/zenmap/zenmapGUI/higwidgets/hignotebooks.py index 5e7d2a7..319d985 100644 --- a/zenmap/zenmapGUI/higwidgets/hignotebooks.py +++ b/zenmap/zenmapGUI/higwidgets/hignotebooks.py @@ -126,12 +126,13 @@ # * * # ***************************************************************************/ +from __future__ import absolute_import import gtk import gobject -from higspinner import HIGSpinner -from higboxes import HIGHBox -from higbuttons import HIGButton +from .higspinner import HIGSpinner +from .higboxes import HIGHBox +from .higbuttons import HIGButton class HIGNotebook(gtk.Notebook): diff --git a/zenmap/zenmapGUI/higwidgets/higprogressbars.py b/zenmap/zenmapGUI/higwidgets/higprogressbars.py index 7c9b15e..a64bb34 100644 --- a/zenmap/zenmapGUI/higwidgets/higprogressbars.py +++ b/zenmap/zenmapGUI/higwidgets/higprogressbars.py @@ -131,12 +131,13 @@ higwidgets/higprogressbars.py progress bars classes """ +from __future__ import absolute_import __all__ = ['HIGLabeledProgressBar'] import gtk -from higboxes import HIGHBox +from .higboxes import HIGHBox class HIGLabeledProgressBar(HIGHBox): diff --git a/zenmap/zenmapGUI/higwidgets/higspinner.py b/zenmap/zenmapGUI/higwidgets/higspinner.py index eefca61..a76bc47 100644 --- a/zenmap/zenmapGUI/higwidgets/higspinner.py +++ b/zenmap/zenmapGUI/higwidgets/higspinner.py @@ -131,17 +131,22 @@ higwidgets/higspinner.py a pygtk spinner, based on the epiphany/nautilus implementation """ +from __future__ import division +from __future__ import absolute_import +from builtins import range +from past.utils import old_div +from builtins import object __all__ = ['HIGSpinner'] import os import gtk import gobject -from gtkutils import gobject_register +from .gtkutils import gobject_register -class HIGSpinnerImages: +class HIGSpinnerImages(object): def __init__(self): """This class holds list of GDK Pixbuffers. @@ -215,7 +220,7 @@ class HIGSpinnerImages: self.images_height = height -class HIGSpinnerCache: +class HIGSpinnerCache(object): """This hols a copy of the images used on the HIGSpinners instances.""" def __init__(self): @@ -429,8 +434,8 @@ class HIGSpinner(gtk.EventBox): width = self.current_pixbuf.get_width() height = self.current_pixbuf.get_height() - x_offset = (self.allocation.width - width) / 2 - y_offset = (self.allocation.height - height) / 2 + x_offset = old_div((self.allocation.width - width), 2) + y_offset = old_div((self.allocation.height - height), 2) pix_area = gtk.gdk.Rectangle(x_offset + self.allocation.x, y_offset + self.allocation.y,