def get_type(arg): """Return the type of the argument (mac, ip, hostname, url, hostport, or username)""" ip_types = { (4, False): "ip", (6, False): "ip6", (4, True): "cidr", (6, True): "cidr6", } if ieeemac.ismac(arg): return 'mac' #macs can look like hashes, so check them first if ishash(arg): return 'hash' ipver = isip(arg) if ipver: return ip_types[(ipver, '/' in arg)] parts = arg.split(':') if len(parts) == 2 and parts[1].isdigit(): return 'hostport' if '://' in arg: return 'url' if '.' in arg: return 'hostname' return 'username'
def find_many_ports_from_string(self, s): data = [] import findipsandmacs import ieeemac for x in findipsandmacs.find(s): p = None mac = None ip = None dns = None try: if ieeemac.ismac(x): p = Port.find(mac=x) mac = x else: p = Port.find(ip=x) ip = x if p and not ip: ips = util.get_ips_for_mac(x) if ips: ip = ips[0] if p and not mac: macs = util.get_macs_for_ip(x) if macs: mac = macs[0] if ip: dns = resolve(ip) data.append((mac, ip, dns, p)) except Exception, e: pass
def find_many_ports_from_string(self, s): data = [] import findipsandmacs import ieeemac for x in findipsandmacs.find(s): p = None mac = None ip = None dns = None try : if ieeemac.ismac(x): p = Port.find(mac=x) mac = x else: p = Port.find(ip=x) ip = x if p and not ip: ips = util.get_ips_for_mac(x) if ips: ip = ips[0] if p and not mac: macs = util.get_macs_for_ip(x) if macs: mac = macs[0] if ip: dns = resolve(ip) data.append((mac, ip, dns, p)) except Exception, e: pass
def get_type(arg): if ieeemac.ismac(arg): return 'mac' if isip(arg): return 'ip' if '.' in arg: return 'hostname' return 'username'
def get_info(self, arg): ret = {} if ieeemac.ismac(arg): mac = arg ret['ips'] = ips = self.db.util.get_ips_for_mac(mac) ip = ips and ips[0] ret["macs"] = [mac] porto = self.db.Port.get_by_mac(mac) else : ip = arg ret["macs"] = self.db.util.get_macs_for_ip(ip) porto = self.db.Port.get_by_ip(ip) if porto: ret['found'] = True ret["switch"], ret["port"] = porto.ip, porto.port else: ret['found'] = False if not porto: for i in 'location','device_location','switchname','portstatus','speed','duplex','duplex_admin', 'device_type', 'description': ret[i] = 'NA' ret['hasbeendisabled'] = False else : d = porto.device if d.location and 'Enter' not in d.location: ret["device_location"] = d.location else : ret["device_location"] = d.name ret["switchname"] = d.name if d.vendor == 'cisco': ret["device_type"] = "switch" else : ret["device_type"] = "hub" ret["portstatus"] = porto.status for i in 'duplex', 'duplex_admin', 'speed': ret[i] = getattr(porto, i) ret["description"] = porto.name ret['hasbeendisabled'] = bool(list(porto.log)) ret['netbios'] = data = False if ip: data = self.db.Node_NBT.query.filter(self.db.Node_NBT.ip==ip).first() if data: ret['netbios'] = True ret['nbname'] = data.nbname ret['domain'] = data.domain ret['nbuser'] = data.nbuser else : ret['nbname'] = ret['domain'] = ret['nbuser'] = None return ret
def get_type(arg): """Return the type of the argument (mac, ip, hostname, or username)""" ip_types = { (4, False): "ip", (6, False): "ip6", (4, True): "cidr", (6, True): "cidr6", } if ieeemac.ismac(arg): return 'mac' #macs can look like hashes, so check them first if ishash(arg): return 'hash' ipver = isip(arg) if ipver: return ip_types[(ipver, '/' in arg)] if '.' in arg: return 'hostname' return 'username'