解决Metasploit调用Nessus报错问题

2024-09-07 10:52

本文主要是介绍解决Metasploit调用Nessus报错问题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

问题描述

Error while running command nessus_scan_new: undefined method `[]’ for nil:NilClass

在这里插入图片描述

解决方法

发现报错,经过网上查询解决方法
在这里插入图片描述
在Nessus服务器执行,下面的版本号可能有所不同,根据自己的情况更改,需要管理员身份执行。

curl "https://raw.githubusercontent.com/QKaiser/nessus_rest-ruby/nessus-protected-api-support/lib/nessus_rest.rb" > /usr/share/metasploit-framework/vendor/bundle/ruby/版本号/gems/nessus_rest-0.1.6/lib/nessus_rest.rb

可能会遇到打不开的情况下,这个时候可以用一台能打开网址的电脑,将内容复制下来粘贴到一个文本文档中,然后将名称命名为nessus_rest.rbNessus服务器中的文件替换掉(建议将原文件改名,然后再将新建的文件放入目标文件夹中即可,以免有问题可以改回来)

https://raw.githubusercontent.com/QKaiser/nessus_rest-ruby/nessus-protected-api-support/lib/nessus_rest.rb

Ps:遇到打不开的童鞋,我把打开的内容贴在文章的最后方便大家直接复制。
然后退出msfconsole,在重新进入msfconsole,加载nessus

exit
msfconsole
load nessus

这个时候发现问题已经解决,能正常执行nessus_scan_new命令
在这里插入图片描述

nessus_rest.rb内容

#!/usr/bin/env ruby
# coding: utf-8
# = nessus_rest.rb: communicate with Nessus(6+) over JSON REST interface
#
# Author:: Vlatko Kosturjak
#
# (C) Vlatko Kosturjak, Kost. Distributed under MIT license.
# 
# == What is this library? 
# 
# This library is used for communication with Nessus over JSON REST interface. 
# You can start, stop, pause and resume scan. Watch progress and status of scan, 
# download report, etc.
#
# == Requirements
# 
# Required libraries are standard Ruby libraries: uri, net/https and json. 
#
# == Usage:
# 
#   require 'nessus_rest'
#
#   n=NessusREST::Client.new ({:url=>'https://localhost:8834', :username=>'user', :password=> 'password'})
#   qs=n.scan_quick_template('basic','name-of-scan','localhost')
#   scanid=qs['scan']['id']
#   n.scan_wait4finish(scanid)
#   n.report_download_file(scanid,'csv','myscanreport.csv')
#require 'openssl'
require 'uri'
require 'net/http'
require 'net/https'
require 'json'# NessusREST module - for all stuff regarding Nessus REST JSON
# module NessusREST# Client class implementation of Nessus (6+) JSON REST protocol. # Class which uses standard JSON lib to parse nessus JSON REST replies. # # == Typical Usage:##   require 'nessus_rest'##   n=NessusREST::Client.new ({:url=>'https://localhost:8834', :username=>'user', :password=> 'password'})#   qs=n.scan_quick_template('basic','name-of-scan','localhost')#   scanid=qs['scan']['id']#   n.scan_wait4finish(scanid)#   n.report_download_file(scanid,'csv','myscanreport.csv')#class Clientattr_accessor :quick_defaultsattr_accessor :defsleep, :httpsleep, :httpretry, :ssl_use, :ssl_verify, :autologinattr_reader :x_cookieclass << self@connection@tokenend# initialize quick scan defaults: these will be used when not specifying defaults## Usage: # #  n.init_quick_defaults()def init_quick_defaults@quick_defaults=Hash.new@quick_defaults['enabled']=false@quick_defaults['launch']='ONETIME'@quick_defaults['launch_now']=true@quick_defaults['description']='Created with nessus_rest'end# initialize object: try to connect to Nessus Scanner using URL, user and password# (or any other defaults)## Usage:##  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')def initialize(params={})# defaults@nessusurl = params.fetch(:url,'https://127.0.0.1:8834/')@username = params.fetch(:username,'nessus')@password = params.fetch(:password,'nessus')@ssl_verify = params.fetch(:ssl_verify,false)@ssl_use = params.fetch(:ssl_use,true)@autologin = params.fetch(:autologin, true)@defsleep = params.fetch(:defsleep, 1)@httpretry = params.fetch(:httpretry, 3)@httpsleep = params.fetch(:httpsleep, 1)init_quick_defaults()uri = URI.parse(@nessusurl)@connection = Net::HTTP.new(uri.host, uri.port)@connection.use_ssl = @ssl_useif @ssl_verify@connection.verify_mode = OpenSSL::SSL::VERIFY_PEERelse@connection.verify_mode = OpenSSL::SSL::VERIFY_NONEendyield @connection if block_given?authenticate(@username, @password) if @autologinend# Tries to authenticate to the Nessus REST JSON interface## returns: true if logged in, false if not## Usage:##  n=NessusREST::Client.new (:url=>'https://localhost:8834', :autologin=>false)#  if n.authenticate('user','pass')#	puts "Logged in"#  else#	puts "Error"#  enddef authenticate(username, password)@username = username@password = passwordauthdefaultendalias_method :login, :authenticate# Tries to authenticate to the Nessus REST JSON interface## returns: true if logged in, false if not## Usage:##  n=NessusREST::Client.new (:url=>'https://localhost:8834', :autologin=>false, #     :username=>'nessususer', :password=>'nessuspassword')#  if n.authdefault#	puts "Logged in"#  else#	puts "Error"#  enddef authdefaultpayload = {:username => @username,:password => @password,:json => 1,:authenticationmethod => true}res = http_post(:uri=>"/session", :data=>payload)if res['token']@token = "token=#{res['token']}"# Starting from Nessus 7.x, Tenable protects some endpoints with a custom header# so that they can only be called from the user interface (supposedly).res = http_get({:uri=>"/nessus6.js", :raw_content=> true})@api_token = res.scan(/([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12})/).first.last@x_cookie = {'X-Cookie'=>@token, 'X-API-Token'=> @api_token}return trueelsefalseendend# checks if we're logged in correctly## returns: true if logged in, false if not## Usage:##  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')#  if n.authenticated#	puts "Logged in"#  else#	puts "Error"#  enddef authenticatedif (@token && @token.include?('token='))return trueelsereturn falseendend# try to get server properties## returns: JSON parsed object with server properties## Usage:##  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')#  pp n.get_server_propertiesdef get_server_propertieshttp_get(:uri=>"/server/properties", :fields=>x_cookie)endalias_method :server_properties, :get_server_properties# Add user to server## returns: JSON parsed object## Usage:##  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')#  pp n.user_add('user','password','16','local')## Reference:# https://localhost:8834/api#/resources/users/createdef user_add(username, password, permissions, type)payload = {:username => username, :password => password, :permissions => permissions, :type => type, :json => 1}http_post(:uri=>"/users", :fields=>x_cookie, :data=>payload)end# delete user with user_id## returns: result code## Usage:##  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')#  puts n.user_delete(1)def user_delete(user_id)res = http_delete(:uri=>"/users/#{user_id}", :fields=>x_cookie)return res.codeend# change password for user_id## returns: result code## Usage:##  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')#  puts n.user_chpasswd(1,'newPassword')def user_chpasswd(user_id, password)payload = {:password => password, :json => 1}res = http_put(:uri=>"/users/#{user_id}/chpasswd", :data=>payload, :fields=>x_cookie)return res.codeend# logout from the server## returns: result code## Usage:##  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')#  puts n.user_logoutdef user_logoutres = http_delete(:uri=>"/session", :fields=>x_cookie)return res.codeendalias_method :logout, :user_logout# Get List of Policies## returns: JSON parsed object with list of policies## Usage:##  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')#  pp n.list_policiesdef list_policieshttp_get(:uri=>"/policies", :fields=>x_cookie)end# Get List of Users## returns: JSON parsed object with list of users## Usage:##  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')#  pp n.list_usersdef list_usershttp_get(:uri=>"/users", :fields=>x_cookie)end# Get List of Folders## returns: JSON parsed object with list of folders## Usage:##  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')#  pp n.list_foldersdef list_foldershttp_get(:uri=>"/folders", :fields=>x_cookie)end# Get List of Scanners## returns: JSON parsed object with list of scanners## Usage:##  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')#  pp n.list_scannersdef list_scannershttp_get(:uri=>"/scanners", :fields=>x_cookie)end# Get List of Families## returns: JSON parsed object with list of families## Usage:##  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')#  pp n.list_familiesdef list_familieshttp_get(:uri=>"/plugins/families", :fields=>x_cookie)end# Get List of Plugins## returns: JSON parsed object with list of plugins## Usage:##  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')#  pp n.list_pluginsdef list_plugins(family_id)http_get(:uri=>"/plugins/families/#{family_id}", :fields=>x_cookie)end# Get List of Templates## returns: JSON parsed object with list of templates## Usage:##  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')#  pp n.list_templatesdef list_templates(type)res = http_get(:uri=>"/editor/#{type}/templates", :fields=>x_cookie)enddef plugin_details(plugin_id)http_get(:uri=>"/plugins/plugin/#{plugin_id}", :fields=>x_cookie)end# check if logged in user is administrator## returns: boolean value depending if user is administrator or not## Usage:##  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')#  if n.is_admin#	puts "Administrator"#  else#	puts "NOT administrator"#  enddef is_adminres = http_get(:uri=>"/session", :fields=>x_cookie)if res['permissions'] == 128return trueelsereturn falseendend# Get server status## returns: JSON parsed object with server status## Usage:##  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')#  pp n.server_statusdef server_statushttp_get(:uri=>"/server/status", :fields=>x_cookie)enddef scan_create(uuid, settings)payload = {:uuid => uuid, :settings => settings,:json => 1}.to_jsonhttp_post(:uri=>"/scans", :body=>payload, :fields=>x_cookie, :ctype=>'application/json')enddef scan_launch(scan_id)http_post(:uri=>"/scans/#{scan_id}/launch", :fields=>x_cookie)end# Get List of Scans## returns: JSON parsed object with list of scans## Usage:##  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')#  pp n.scan_listdef scan_listhttp_get(:uri=>"/scans", :fields=>x_cookie)endalias_method :list_scans, :scan_listdef scan_details(scan_id)http_get(:uri=>"/scans/#{scan_id}", :fields=>x_cookie)enddef scan_pause(scan_id)http_post(:uri=>"/scans/#{scan_id}/pause", :fields=>x_cookie)enddef scan_resume(scan_id)http_post(:uri=>"/scans/#{scan_id}/resume", :fields=>x_cookie)enddef scan_stop(scan_id)http_post(:uri=>"/scans/#{scan_id}/stop", :fields=>x_cookie)enddef scan_export(scan_id, format)payload = {:format => format}.to_jsonhttp_post(:uri=>"/scans/#{scan_id}/export", :body=>payload, :ctype=>'application/json', :fields=>x_cookie)enddef scan_export_status(scan_id, file_id)request = Net::HTTP::Get.new("/scans/#{scan_id}/export/#{file_id}/status")request.add_field("X-Cookie", @token)res = @connection.request(request)res = JSON.parse(res.body)return resend# delete scan with scan_id## returns: boolean (true if deleted)## Usage:##  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')#  puts n.scan_delete(1)def scan_delete(scan_id)res = http_delete(:uri=>"/scans/#{scan_id}", :fields=>x_cookie)if res.code == 200 thenreturn trueendreturn falseenddef policy_delete(policy_id)res = http_delete(:uri=>"/policies/#{policy_id}", :fields=>x_cookie)return res.codeend# Get template by type and uuid. Type can be 'policy' or 'scan'## returns: JSON parsed object with template## Usage:##  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')#  pp n.editor_templates('scan',uuid)def editor_templates (type, uuid)res = http_get(:uri=>"/editor/#{type}/templates/#{uuid}", :fields=>x_cookie)end# Performs scan with templatename provided (name, title or uuid of scan).# Name is your scan name and targets are targets for scan## returns: JSON parsed object with scan info## Usage:##   require 'nessus_rest'##   n=NessusREST::Client.new ({:url=>'https://localhost:8834', :username=>'user', :password=> 'password'})#   qs=n.scan_quick_template('basic','name-of-scan','localhost')#   scanid=qs['scan']['id']#   n.scan_wait4finish(scanid)#   n.report_download_file(scanid,'csv','myscanreport.csv')#def scan_quick_template (templatename, name, targets)templates=list_templates('scan')['templates'].select do |temp| temp['uuid'] == templatename or temp['name'] == templatename or temp['title'] == templatenameendif templates.nil? thenreturn nilendtuuid=templates.first['uuid']et=editor_templates('scan',tuuid)et.merge!(@quick_defaults)et['name']=nameet['text_targets']=targetssc=scan_create(tuuid,et)end# Performs scan with scan policy provided (uuid of policy or policy name).# Name is your scan name and targets are targets for scan## returns: JSON parsed object with scan info## Usage:##   require 'nessus_rest'##   n=NessusREST::Client.new ({:url=>'https://localhost:8834', :username=>'user', :password=> 'password'})#   qs=n.scan_quick_policy('myscanpolicy','name-of-scan','localhost')#   scanid=qs['scan']['id']#   n.scan_wait4finish(scanid)#   n.report_download_file(scanid,'nessus','myscanreport.nessus')#def scan_quick_policy (policyname, name, targets)policies=list_policies['policies'].select do |pol|pol['id'] == policyname or pol['name'] == policynameendif policies.nil? thenreturn nilendpolicy = policies.firsttuuid=policy['template_uuid']et=Hash.newet.merge!(@quick_defaults)et['name']=nameet['policy_id'] = policy['id']et['text_targets']=targetssc=scan_create(tuuid,et)enddef scan_status(scan_id)sd=scan_details(scan_id)if not sd['error'].nil?return 'error'endreturn sd['info']['status']enddef scan_finished?(scan_id)ss=scan_status(scan_id)if ss == 'completed' or ss == 'canceled' or ss == 'imported' thenreturn trueendreturn falseenddef scan_wait4finish(scan_id)while not scan_finished?(scan_id) do# puts scan_status(scan_id)sleep @defsleependend# Get host details from the scan## returns: JSON parsed object with host details## Usage:##  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')#  pp n.host_detail(123, 1234)def host_detail(scan_id, host_id)res = http_get(:uri=>"/scans/#{scan_id}/hosts/#{host_id}", :fields=>x_cookie)enddef report_download(scan_id, file_id)res = http_get(:uri=>"/scans/#{scan_id}/export/#{file_id}/download", :raw_content=> true, :fields=>x_cookie)enddef report_download_quick(scan_id, format) se=scan_export(scan_id,format)# ready, loadingwhile (status = scan_export_status(scan_id,se['file'])['status']) != "ready" do# puts statusif status.nil? or status == '' thenreturn nilendsleep @defsleependrf=report_download(scan_id,se['file'])return rfenddef report_download_file(scan_id, format, outputfn)report_content=report_download_quick(scan_id, format)File.open(outputfn, 'w') do |f| f.write(report_content)endend## private?## Perform HTTP put method with uri, data and fields## returns: HTTP result object## Usage:##  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')#  payload = {#    :password => password, #    :json => 1#  }#  res = n.http_put(:uri=>"/users/#{user_id}/chpasswd", :data=>payload, :fields=>n.x_cookie)#  puts res.code def http_put(opts={})ret=http_put_low(opts)if ret.is_a?(Hash) and ret.has_key?('error') and ret['error']=='Invalid Credentials' thenauthdefaultret=http_put_low(opts)return retelsereturn retendenddef http_put_low(opts={})uri    = opts[:uri]data   = opts[:data]fields = opts[:fields] || {}res    = niltries  = @httpretryreq = Net::HTTP::Put.new(uri)req.set_form_data(data) unless (data.nil? || data.empty?)fields.each_pair do |name, value|req.add_field(name, value)endbegintries -= 1res = @connection.request(req)rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => eif tries>0sleep @httpsleepretryelsereturn resendrescue URI::InvalidURIErrorreturn resendresend# Perform HTTP delete method with uri, data and fields## returns: HTTP result object## Usage:##  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')#  res = n.http_delete(:uri=>"/session", :fields=>n.x_cookie)#  puts res.codedef http_delete(opts={})ret=http_delete_low(opts)if ret.is_a?(Hash) and ret.has_key?('error') and ret['error']=='Invalid Credentials' thenauthdefaultret=http_delete_low(opts)return retelsereturn retendenddef http_delete_low(opts={})uri    = opts[:uri]fields = opts[:fields] || {}res    = niltries  = @httpretryreq = Net::HTTP::Delete.new(uri)fields.each_pair do |name, value|req.add_field(name, value)endbegintries -= 1res = @connection.request(req)rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => eif tries>0sleep @httpsleepretryelsereturn resendrescue URI::InvalidURIErrorreturn resendresend# Perform HTTP get method with uri and fields## returns: JSON parsed object (if JSON parseable)## Usage:##  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')#  pp n.http_get(:uri=>"/users", :fields=>n.x_cookie)def http_get(opts={})raw_content = opts[:raw_content] || falseret=http_get_low(opts)if !raw_content thenif ret.is_a?(Hash) and ret.has_key?('error') and ret['error']=='Invalid Credentials' thenauthdefaultret=http_get_low(opts)return retelsereturn retendelsereturn retendenddef http_get_low(opts={})uri    = opts[:uri]fields = opts[:fields] || {}raw_content = opts[:raw_content] || falsejson   = {}tries  = @httpretryreq = Net::HTTP::Get.new(uri)fields.each_pair do |name, value|req.add_field(name, value)endbegintries -= 1res = @connection.request(req)rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => eif tries>0sleep @httpsleepretryelsereturn jsonendrescue URI::InvalidURIErrorreturn jsonendif !raw_contentparse_json(res.body)elseres.bodyendend# Perform HTTP post method with uri, data, body and fields## returns: JSON parsed object (if JSON parseable)## Usage:##  n=NessusREST::Client.new (:url=>'https://localhost:8834', :username=>'user', :password=> 'password')#  pp n.http_post(:uri=>"/scans/#{scan_id}/launch", :fields=>n.x_cookie)def http_post(opts={})if opts.has_key?(:authenticationmethod) then# i know authzmethod = opts.delete(:authorizationmethod) is short, but not readableauthzmethod = opts[:authenticationmethod]opts.delete(:authenticationmethod)endret=http_post_low(opts)if ret.is_a?(Hash) and ret.has_key?('error') and ret['error']=='Invalid Credentials' thenif not authzmethodauthdefaultret=http_post_low(opts)return retendelsereturn retendenddef http_post_low(opts={})uri    = opts[:uri]data   = opts[:data]fields = opts[:fields] || {}body   = opts[:body]ctype  = opts[:ctype]json   = {}tries  = @httpretryreq = Net::HTTP::Post.new(uri)req.set_form_data(data) unless (data.nil? || data.empty?)req.body = body unless (body.nil? || body.empty?)req['Content-Type'] = ctype unless (ctype.nil? || ctype.empty?)fields.each_pair do |name, value|req.add_field(name, value)endbegintries -= 1res = @connection.request(req)rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => eif tries>0sleep @httpsleepretryelsereturn jsonendrescue URI::InvalidURIErrorreturn jsonendparse_json(res.body)end# Perform JSON parsing of body## returns: JSON parsed object (if JSON parseable)#def parse_json(body)buf = {}beginbuf = JSON.parse(body)rescue JSON::ParserErrorendbufendend # of Client class
end # of NessusREST module

这篇关于解决Metasploit调用Nessus报错问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1144862

相关文章

好题——hdu2522(小数问题:求1/n的第一个循环节)

好喜欢这题,第一次做小数问题,一开始真心没思路,然后参考了网上的一些资料。 知识点***********************************无限不循环小数即无理数,不能写作两整数之比*****************************(一开始没想到,小学没学好) 此题1/n肯定是一个有限循环小数,了解这些后就能做此题了。 按照除法的机制,用一个函数表示出来就可以了,代码如下

hdu1043(八数码问题,广搜 + hash(实现状态压缩) )

利用康拓展开将一个排列映射成一个自然数,然后就变成了普通的广搜题。 #include<iostream>#include<algorithm>#include<string>#include<stack>#include<queue>#include<map>#include<stdio.h>#include<stdlib.h>#include<ctype.h>#inclu

如何在页面调用utility bar并传递参数至lwc组件

1.在app的utility item中添加lwc组件: 2.调用utility bar api的方式有两种: 方法一,通过lwc调用: import {LightningElement,api ,wire } from 'lwc';import { publish, MessageContext } from 'lightning/messageService';import Ca

如何解决线上平台抽佣高 线下门店客流少的痛点!

目前,许多传统零售店铺正遭遇客源下降的难题。尽管广告推广能带来一定的客流,但其费用昂贵。鉴于此,众多零售商纷纷选择加入像美团、饿了么和抖音这样的大型在线平台,但这些平台的高佣金率导致了利润的大幅缩水。在这样的市场环境下,商家之间的合作网络逐渐成为一种有效的解决方案,通过资源和客户基础的共享,实现共同的利益增长。 以最近在上海兴起的一个跨行业合作平台为例,该平台融合了环保消费积分系统,在短

购买磨轮平衡机时应该注意什么问题和技巧

在购买磨轮平衡机时,您应该注意以下几个关键点: 平衡精度 平衡精度是衡量平衡机性能的核心指标,直接影响到不平衡量的检测与校准的准确性,从而决定磨轮的振动和噪声水平。高精度的平衡机能显著减少振动和噪声,提高磨削加工的精度。 转速范围 宽广的转速范围意味着平衡机能够处理更多种类的磨轮,适应不同的工作条件和规格要求。 振动监测能力 振动监测能力是评估平衡机性能的重要因素。通过传感器实时监

缓存雪崩问题

缓存雪崩是缓存中大量key失效后当高并发到来时导致大量请求到数据库,瞬间耗尽数据库资源,导致数据库无法使用。 解决方案: 1、使用锁进行控制 2、对同一类型信息的key设置不同的过期时间 3、缓存预热 1. 什么是缓存雪崩 缓存雪崩是指在短时间内,大量缓存数据同时失效,导致所有请求直接涌向数据库,瞬间增加数据库的负载压力,可能导致数据库性能下降甚至崩溃。这种情况往往发生在缓存中大量 k

6.1.数据结构-c/c++堆详解下篇(堆排序,TopK问题)

上篇:6.1.数据结构-c/c++模拟实现堆上篇(向下,上调整算法,建堆,增删数据)-CSDN博客 本章重点 1.使用堆来完成堆排序 2.使用堆解决TopK问题 目录 一.堆排序 1.1 思路 1.2 代码 1.3 简单测试 二.TopK问题 2.1 思路(求最小): 2.2 C语言代码(手写堆) 2.3 C++代码(使用优先级队列 priority_queue)

pip-tools:打造可重复、可控的 Python 开发环境,解决依赖关系,让代码更稳定

在 Python 开发中,管理依赖关系是一项繁琐且容易出错的任务。手动更新依赖版本、处理冲突、确保一致性等等,都可能让开发者感到头疼。而 pip-tools 为开发者提供了一套稳定可靠的解决方案。 什么是 pip-tools? pip-tools 是一组命令行工具,旨在简化 Python 依赖关系的管理,确保项目环境的稳定性和可重复性。它主要包含两个核心工具:pip-compile 和 pip

【VUE】跨域问题的概念,以及解决方法。

目录 1.跨域概念 2.解决方法 2.1 配置网络请求代理 2.2 使用@CrossOrigin 注解 2.3 通过配置文件实现跨域 2.4 添加 CorsWebFilter 来解决跨域问题 1.跨域概念 跨域问题是由于浏览器实施了同源策略,该策略要求请求的域名、协议和端口必须与提供资源的服务相同。如果不相同,则需要服务器显式地允许这种跨域请求。一般在springbo

题目1254:N皇后问题

题目1254:N皇后问题 时间限制:1 秒 内存限制:128 兆 特殊判题:否 题目描述: N皇后问题,即在N*N的方格棋盘内放置了N个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在同一斜线上。因为皇后可以直走,横走和斜走如下图)。 你的任务是,对于给定的N,求出有多少种合法的放置方法。输出N皇后问题所有不同的摆放情况个数。 输入