def list(self, request, **kwargs): try: ipaddress = request.query_params.get('ipaddress', None) context = PortService.list(ipaddress=ipaddress) except Exception as E: logger.error(E) context = data_return(500, CODE_MSG.get(500), []) return Response(context)
def list(): hosts = Host.list_hosts() for host in hosts: hid = host.get('id') host['portService'] = PortService.list_by_hid(hid) context = data_return(200, CODE_MSG.get(200), hosts) return context
def list(): hosts = Host.list_hosts() for host in hosts: ipaddress = host.get('ipaddress') host['portService'] = PortService.list_by_ipaddress(ipaddress) context = data_return(200, CODE_MSG.get(200), hosts) return context
def list(self, request, **kwargs): try: hid = int(request.query_params.get('hid', None)) context = PortService.list(hid=hid) except Exception as E: logger.error(E) context = data_return(500, CODE_MSG.get(500), []) return Response(context)
def destroy(self, request, pk=None, **kwargs): try: ipaddress = request.query_params.get('ipaddress', None) port = int(request.query_params.get('port', None)) context = PortService.destory(ipaddress=ipaddress, port=port) except Exception as E: logger.error(E) context = data_return(500, CODE_MSG.get(500), {}) return Response(context)
def add_portservice(self, ipaddress, port, banner=None, service=""): """增加一个端口/服务信息""" if banner is None: banner = {} if isinstance(banner, dict) is not True: logger.warning('数据类型检查错误,数据 {}'.format(banner)) banner = {} result = PortService.add_or_update(ipaddress=ipaddress, port=port, banner=banner, service=service) return result
def add_portservice(self, hid, port, proxy=None, banner=None, service=""): if proxy is None: proxy = {} if banner is None: banner = {} # 数据类型检查 if isinstance(proxy, dict) is not True: logger.warning('数据类型检查错误,数据 {}'.format(proxy)) proxy = {} if isinstance(banner, dict) is not True: logger.warning('数据类型检查错误,数据 {}'.format(banner)) banner = {} result = PortService.add_or_update(hid=hid, port=port, proxy=proxy, banner=banner, service=service) return result