Class: SharedTools::Tools::DnsTool
- Inherits:
-
RubyLLM::Tool
- Object
- RubyLLM::Tool
- SharedTools::Tools::DnsTool
- Defined in:
- lib/shared_tools/tools/dns_tool.rb
Overview
A tool for performing DNS lookups and reverse DNS queries. Uses Ruby’s built-in Resolv library for cross-platform support.
Class Method Summary collapse
Instance Method Summary collapse
-
#execute(action:, hostname: nil, ip: nil, record_type: nil) ⇒ Hash
Execute DNS action.
-
#initialize(logger: nil) ⇒ DnsTool
constructor
A new instance of DnsTool.
Constructor Details
#initialize(logger: nil) ⇒ DnsTool
Returns a new instance of DnsTool.
85 86 87 |
# File 'lib/shared_tools/tools/dns_tool.rb', line 85 def initialize(logger: nil) @logger = logger || RubyLLM.logger end |
Class Method Details
.name ⇒ Object
17 |
# File 'lib/shared_tools/tools/dns_tool.rb', line 17 def self.name = 'dns' |
Instance Method Details
#execute(action:, hostname: nil, ip: nil, record_type: nil) ⇒ Hash
Execute DNS action
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/shared_tools/tools/dns_tool.rb', line 96 def execute(action:, hostname: nil, ip: nil, record_type: nil) @logger.info("DnsTool#execute action=#{action.inspect}") case action.to_s.downcase when 'lookup' lookup(hostname, record_type || 'A') when 'reverse' reverse_lookup(ip) when 'mx' mx_lookup(hostname) when 'txt' txt_lookup(hostname) when 'ns' ns_lookup(hostname) when 'all' all_records(hostname) else { success: false, error: "Unknown action: #{action}. Valid actions are: lookup, reverse, mx, txt, ns, all" } end rescue Resolv::ResolvError => e @logger.error("DnsTool DNS error: #{e.message}") { success: false, error: "DNS resolution failed: #{e.message}" } rescue => e @logger.error("DnsTool error: #{e.message}") { success: false, error: e. } end |