本文整理汇总了Python中zenmapCore.UmitLogging.log.debug函数的典型用法代码示例。如果您正苦于以下问题:Python debug函数的具体用法?Python debug怎么用?Python debug使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了debug函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: wrap_file_in_preferred_encoding
def wrap_file_in_preferred_encoding(f):
"""Wrap an open file to automatically decode its contents when reading from
the encoding given by locale.getpreferredencoding, or just return the file
if that doesn't work.
The nmap executable will write its output in whatever the system encoding
is. Nmap's output is usually all ASCII, but time zone it prints can be in a
different encoding. If it is not decoded correctly it will be displayed as
garbage characters. This function assists in reading the Nmap output. We
don't know for sure what the encoding used is, but we take a best guess and
decode the output into a proper unicode object so that the screen display
and XML writer interpret it correctly."""
try:
preferredencoding = locale.getpreferredencoding()
except locale.Error:
# This can happen if the LANG environment variable is set to something
# weird.
preferredencoding = None
if preferredencoding is not None:
try:
reader = codecs.getreader(preferredencoding)
return reader(f, "replace")
except LookupError:
# The lookup failed. This can happen if the preferred encoding is
# unknown ("X-MAC-KOREAN" has been observed). Ignore it and return
# the unwrapped file.
log.debug("Unknown encoding \"%s\"." % preferredencoding)
return f
示例2: __get_it
def __get_it(self, p_name, default):
try:
return config_parser.get(self.section_name, p_name)
except (NoOptionError, NoSectionError):
log.debug(
">>> Using default \"%s\" for \"%s\"." % (default, p_name))
return default
示例3: match_profile
def match_profile(self, profile):
log.debug("Match profile: %s" % profile)
log.debug("Comparing: %s == %s ??" % (
str(self.parsed_scan.profile_name).lower(),
"*%s*" % profile.lower()))
return (profile == "*" or profile == "" or
profile.lower() in str(self.parsed_scan.profile_name).lower())
示例4: match_option
def match_option(self, option):
log.debug("Match option: %s" % option)
if option == "*" or option == "":
return True
# NOTE: Option matching treats "_" and "-" the same, just like the
# optcmp function in utils.cc . Also, option matching is
# case-sensitive.
option = option.replace("_", "-")
ops = NmapOptions()
ops.parse_string(self.parsed_scan.get_nmap_command())
if "(" in option and ")" in option:
# The syntax allows matching option arguments as
# "opt:option_name(value)". Since we've received only the
# "option_name(value)" part, we need to parse it.
optname = option[:option.find("(")]
optval = option[option.find("(") + 1:option.find(")")]
val = ops["--" + optname]
if val is None:
val = ops["-" + optname]
if val is None:
return False
return str(val) == optval or str(val) == optval
else:
return (ops["--" + option] is not None or
ops["-" + option] is not None)
示例5: read
def read(self, filename):
log.debug(">>> Trying to parse: %s" % filename)
if ConfigParser.read(self, filename):
self.filenames = filename
return self.filenames
示例6: run_scan
def run_scan(self, stderr = None):
"""Run the command represented by this class."""
# We don't need a file name for stdout output, just a handle. A
# TemporaryFile is deleted as soon as it is closed, and in Unix is
# unlinked immediately after creation so it's not even visible.
f = tempfile.TemporaryFile(mode = "rb", prefix = APP_NAME + "-stdout-")
self.stdout_file = wrap_file_in_preferred_encoding(f)
if stderr is None:
stderr = f
search_paths = self.get_path()
env = dict(os.environ)
env["PATH"] = search_paths
log.debug("PATH=%s" % env["PATH"])
command_list = self.ops.render()
log.debug("Running command: %s" % repr(command_list))
startupinfo = None
if sys.platform == "win32":
# This keeps a terminal window from opening.
startupinfo = subprocess.STARTUPINFO()
try:
startupinfo.dwFlags |= subprocess._subprocess.STARTF_USESHOWWINDOW
except AttributeError:
# This name is used before Python 2.6.5.
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
self.command_process = subprocess.Popen(command_list, bufsize=1,
stdin=subprocess.PIPE,
stdout=f,
stderr=stderr,
startupinfo = startupinfo,
env=env)
示例7: refresh_diff
def refresh_diff(self, widget):
"""This method is called whenever the diff output might have changed,
such as when a different scan was selected in one of the choosers."""
log.debug("Refresh diff.")
if (self.ndiff_process is not None and
self.ndiff_process.poll() is None):
# Put this in the list of old processes we keep track of.
self.old_processes.append(self.ndiff_process)
self.ndiff_process = None
scan_a = self.scan_chooser_a.parsed_scan
scan_b = self.scan_chooser_b.parsed_scan
if scan_a is None or scan_b is None:
self.diff_view.clear()
else:
try:
self.ndiff_process = zenmapCore.Diff.ndiff(scan_a, scan_b)
except OSError, e:
alert = HIGAlertDialog(
message_format=_("Error running ndiff"),
secondary_text=_(
"There was an error running the ndiff program.\n\n"
) + str(e).decode(sys.getdefaultencoding(), "replace"))
alert.run()
alert.destroy()
else:
示例8: verify_execution
def verify_execution(self):
"""This is a callback that is called periodically to refresh the output
check whether any running scans have finished. The timer that schedules
the callback is started in execute_command. When there are no more
running scans, this function returns True so that it won't be scheduled
again."""
self.scan_result.refresh_nmap_output()
finished_jobs = []
for scan in self.jobs:
try:
alive = scan.scan_state()
if alive:
continue
except:
log.debug("Scan terminated unexpectedly: %s" % scan.command)
self.scans_store.fail_running_scan(scan)
else:
log.debug("Scan finished: %s" % scan.command)
self.load_from_command(scan)
scan.close()
self.update_cancel_button()
finished_jobs.append(scan)
# Remove finished jobs from the job list
for finished in finished_jobs:
self.jobs.remove(finished)
del(finished_jobs)
return len(self.jobs) != 0
示例9: refresh_output
def refresh_output(self, widget = None):
"""Update the output from the latest output of the command associated
with this view, as set by set_command_execution. It has no effect if no
command has been set."""
log.debug("Refresh nmap output")
if self.command_execution is None:
return
# Seek to the end of the most recent read.
self.command_execution.stdout_file.seek(self.output_file_pointer)
pos = self.command_execution.stdout_file.tell()
new_output = self.command_execution.stdout_file.read()
self.output_file_pointer = self.command_execution.stdout_file.tell()
# print "read %d -> %d %d" % (pos, self.output_file_pointer, len(new_output))
v_adj = self.scrolled.get_vadjustment()
if new_output and v_adj is not None:
# Find out if the view is already scrolled to the bottom.
at_end = (v_adj.value >= v_adj.upper - v_adj.page_size)
buf = self.text_view.get_buffer()
prev_end_mark = buf.create_mark(None, buf.get_end_iter(), left_gravity = True)
buf.insert(buf.get_end_iter(), new_output)
# Highlight the new text.
self.apply_highlighting(buf.get_iter_at_mark(prev_end_mark), buf.get_end_iter())
if at_end:
# If we were already scrolled to the bottom, scroll back to the
# bottom again. Also do it in an idle handler in case the added
# text causes a scroll bar to appear and reflow the text, making
# the text a bit taller.
self.text_view.scroll_mark_onscreen(self.end_mark)
gobject.idle_add(lambda: self.text_view.scroll_mark_onscreen(self.end_mark))
示例10: kill
def kill(self):
"""Kill the nmap subprocess."""
from time import sleep
log.debug(">>> Killing scan process %s" % self.command_process.pid)
if sys.platform != "win32":
try:
from signal import SIGTERM, SIGKILL
os.kill(self.command_process.pid, SIGTERM)
for i in range(10):
sleep(0.5)
if self.command_process.poll() is not None: # Process has been TERMinated
break
else:
log.debug(">>> SIGTERM has not worked even after waiting for 5 seconds. Using SIGKILL.")
os.kill(self.command_process.pid, SIGKILL)
self.command_process.wait()
except:
pass
else:
try:
import ctypes
ctypes.windll.kernel32.TerminateProcess(
int(self.command_process._handle), -1)
except:
pass
示例11: close
def close(self):
"""Clean up temporary files."""
self.stdout_file.close()
for filename in self.temporary_filenames:
log.debug("Remove temporary diff file %s." % filename)
os.remove(filename)
self.temporary_filenames = []
示例12: _destroy_callback
def _destroy_callback(window):
open_windows.remove(window)
if len(open_windows) == 0:
gtk.main_quit()
try:
from zenmapCore.UmitDB import UmitDB
except ImportError, e:
log.debug(">>> Not cleaning up database: %s." % str(e))
示例13: safe_shutdown
def safe_shutdown(signum, stack):
"""Kills any active scans/tabs and shuts down the application."""
log.debug("\n\n%s\nSAFE SHUTDOWN!\n%s\n" % ("#" * 30, "#" * 30))
log.debug("SIGNUM: %s" % signum)
for window in open_windows:
window.scan_interface.kill_all_scans()
sys.exit(signum)
示例14: match_target
def match_target(self, target):
log.debug("Match target: %s" % target)
for spec in self.parsed_scan.get_targets():
if target in spec:
return True
else:
# We search the (rDNS) hostnames list
for host in self.parsed_scan.get_hosts():
if HostSearch.match_target(host, target):
return True
return False
示例15: add_to_host_list
def add_to_host_list(self, host, p):
entry = [
"",
findout_service_icon(p),
host,
host.get_hostname(),
int(p.get("portid", "0")),
p.get("protocol", ""),
p.get("port_state", ""),
get_version_string(p),
]
log.debug(">>> Add Host: %s" % entry)
self.host_list.append(entry)