From 96ae8abf6cfec45d52d3fd8367760087e6aaaf40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Kub=C3=AD=C4=8Dek?= Date: Sat, 9 Mar 2024 06:12:12 +0100 Subject: [PATCH] reverse dns --- examples/nic.rb | 1 + lib/xmon.rb | 1 + lib/xmon/descriptions.rb | 7 ++++++- lib/xmon/reverse_dns.rb | 25 +++++++++++++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 lib/xmon/reverse_dns.rb diff --git a/examples/nic.rb b/examples/nic.rb index 81e572a..57a6105 100644 --- a/examples/nic.rb +++ b/examples/nic.rb @@ -15,6 +15,7 @@ end ipv4 "217.31.205.50" do + ptr "www.nic.cz" tcp 80 do status :open end diff --git a/lib/xmon.rb b/lib/xmon.rb index 97aa2ca..2015d8a 100644 --- a/lib/xmon.rb +++ b/lib/xmon.rb @@ -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 diff --git a/lib/xmon/descriptions.rb b/lib/xmon/descriptions.rb index ce44258..7291b40 100644 --- a/lib/xmon/descriptions.rb +++ b/lib/xmon/descriptions.rb @@ -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 @@ -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(&) diff --git a/lib/xmon/reverse_dns.rb b/lib/xmon/reverse_dns.rb new file mode 100644 index 0000000..48741de --- /dev/null +++ b/lib/xmon/reverse_dns.rb @@ -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