diff --git a/lib/ssh_scan/scan_engine.rb b/lib/ssh_scan/scan_engine.rb index 1a4bda2d..ce7bd0c5 100644 --- a/lib/ssh_scan/scan_engine.rb +++ b/lib/ssh_scan/scan_engine.rb @@ -47,7 +47,7 @@ def scan_target(socket, opts) client = SSHScan::Client.new(target, port, timeout) client.connect() result = client.get_kex_result() - result[:hostname] = "" + result[:hostname] = target.resolve_ptr return result if result.include?(:error) end diff --git a/lib/string_ext.rb b/lib/string_ext.rb index 4db4022d..6584dbfb 100644 --- a/lib/string_ext.rb +++ b/lib/string_ext.rb @@ -55,7 +55,18 @@ def resolve_fqdn_as_ipv4(timeout = 3) end def resolve_fqdn - @fqdn ||= TCPSocket.gethostbyname(self)[3] + TCPSocket.gethostbyname(self)[3] + end + + def resolve_ptr(timeout = 3) + begin + Timeout::timeout(timeout) { + reversed_dns = Resolv.new.getname(self) + return reversed_dns + } + rescue Timeout::Error + return "" + end end def fqdn?