Skip to content

Commit

Permalink
reverse dns
Browse files Browse the repository at this point in the history
  • Loading branch information
kubicek committed Mar 9, 2024
1 parent 240e862 commit 96ae8ab
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions examples/nic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
end

ipv4 "217.31.205.50" do
ptr "www.nic.cz"
tcp 80 do
status :open
end
Expand Down
1 change: 1 addition & 0 deletions lib/xmon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
require_relative "xmon/ssl"
require_relative "xmon/dns"
require_relative "xmon/rdap"
require_relative "xmon/reverse_dns"

module Xmon
class Error < StandardError; end
Expand Down
7 changes: 6 additions & 1 deletion lib/xmon/descriptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def describe(*args, **kwargs, &)
if block_given?
@description.instance_eval(&)
else
@description = @description.class.new(*args, **kwargs)
# @description = @description.class.new(*args, **kwargs)
end
@descriptions ||= []
@descriptions << @description
Expand Down Expand Up @@ -92,6 +92,11 @@ def friendly_name
@address
end

def ptr(*, **, &)
@description = Xmon::ReverseDNS.new(self, *, **)
describe(&)
end

def udp(*, **, &)
@description = Xmon::UDP.new(self, *, **)
describe(&)
Expand Down
25 changes: 25 additions & 0 deletions lib/xmon/reverse_dns.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require "dnsruby"

module Xmon
class ReverseDNS < Description
def initialize(parent, value = nil)
if parent
puts "NEW REVERSE DNS #{value} #{parent.address}"
@parent = parent
@address = parent.address
@hostname = value
else
puts "NEW REVERSE DNS #{value}"
end
end

def fetch(record, type = "A")
puts "fetching #{record} #{type}"
Dnsruby::Resolver.new.query(record, type).answer.map { |a| a.rdata.to_s }.join
end

def check
[Xmon.compare(@hostname, fetch(@address, "PTR"), self)]
end
end
end

0 comments on commit 96ae8ab

Please sign in to comment.