def get_info(self, arg): if util.get_type(arg) == "mac": field = self.field_mac #work around jira being dumb: #Unable to parse the text '00:11:22:33:44:55' for field 'MAC Address'. arg = ieeemac.Mac(arg).to_unix.replace(":", " ") elif util.get_type(arg) == 'hostname': field = self.field_hn else: field = self.field_ip q = 'project="%s" AND "%s" ~ "%s"' % (self.project, field, arg) issues = self.jira.search_issues(q) issue_dicts = [issue.raw for issue in issues] return {"issues": issue_dicts}
def convert(self, arg, to_type): arg_type = util.get_type(arg) for p in self.plugins: try: if (arg_type, to_type) in p.converters: p.init() yield p.name, p.get_converter(arg_type, to_type)(arg) except Exception: logger.exception("Error running plugin %s", p.name)
def convert(self, arg, to_type): arg_type = util.get_type(arg) for p in self.plugins: try: if (arg_type, to_type) in p.converters: p.init() yield p.name, p.get_converter(arg_type, to_type)(arg) except PluginError: logger.exception("Error running plugin %s", p.name)
def compatible_argument(self, plugin, arg): plug = self.get_plugin(plugin) arg_type = util.get_type(arg) if arg_type not in plug.types: logger.debug("Skipping plugin %s because arg is the wrong type" % plugin) return False if arg_type == 'ip': if plug.local == False and self.is_local(arg): logger.debug("Skipping plugin %s because arg is local" % plugin) return False if plug.remote == False and not self.is_local(arg): logger.debug("Skipping plugin %s because arg is remote" % plugin) return False return True
def get_info(self, arg): argtype = util.get_type(arg) print "ieeedb plugin type was " + argtype if argtype == 'mac': conn = psycopg2.connect("dbname=ouilookup user=%s" %(username)) cur = conn.cursor() mac_org = (macaddr.replace(':', '')[:6]).upper() cur.execute("select manufacturer from ouilookup where '%s' = oui;" %(mac_org)) try: prompt = cur.fetchone()[0] except: prompt = "Update the database" else: prompt = "Invalid input" print prompt.__dict__
def compatible_argument(self, plugin, arg): plug = self.get_plugin(plugin) if not plug: logger.debug("Skipping plugin %s because plugin does not exist" % plugin) return False arg_type = util.get_type(arg) if arg_type not in plug.types: logger.debug("Skipping plugin %s because arg is the wrong type" % plugin) return False if arg_type in ['ip', 'ip6']: if plug.local == False and self.is_local(arg): logger.debug("Skipping plugin %s because arg is local" % plugin) return False if plug.remote == False and not self.is_local(arg): logger.debug("Skipping plugin %s because arg is remote" % plugin) return False return True
def get_info(self, arg): with warnings.catch_warnings(): # catching the super annoying warnings regarding insecure connections. warnings.filterwarnings("ignore", ".*Unverified.*") argtype = util.get_type(arg) if argtype == 'hostname': # If we have a hostname, it might be a CNAME, so naively try resolving it. # CNAMEs aren't host records according to Infoblox, so just searching # for the CNAME will return nothing. If we do hostname -> IP and back again, # that should work. try: hname = socket.gethostbyaddr(socket.gethostbyname(arg))[0] host = self.api.get_host(hname) extattrs = self.api.get_host_extattrs(hname) except: # Something's gone really wrong return {'_ref': None } elif argtype == 'ip': try: res = socket.gethostbyaddr(ipaddr) return self.get_info(res[0]) except: pass try: hostname = self.api.get_host_by_ip(arg)[0] return self.get_info(hostname) except: return {'_ref' : None } out = self.format_out(host, extattrs) if (out['_ref'] == None): return out out['type'] = 'hostname' out['dns_name'] = host['ipv4addrs'][0]['host'] out['ipv4addr'] = host['ipv4addrs'][0]['ipv4addr'] return out
def is_local(self, arg): if util.get_type(arg) != "ip": return False return util.is_local(self.local_networks, arg)
def is_local(self, arg): if util.get_type(arg) not in ["ip", "ip6"]: return False return util.is_local(self.local_networks, arg)
def type_case(x, expected_type): eq_(util.get_type(x), expected_type)