Skip to content

Commit

Permalink
Update the presentation of static entries
Browse files Browse the repository at this point in the history
Keep the first line blank for consistency with rules and sort hostnames
and addresses.
  • Loading branch information
zeroSteiner committed Mar 19, 2024
1 parent 9c4f040 commit 63b3ad2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions lib/msf/ui/console/command_dispatcher/dns.rb
Original file line number Diff line number Diff line change
Expand Up @@ -644,11 +644,16 @@ def print_dns
'SortIndex' => -1,
'WordWrap' => false
)
resolver.static_hostnames.each do |hostname, addresses|
ipv4_addresses = addresses.fetch(Dnsruby::Types::A, [])
ipv6_addresses = addresses.fetch(Dnsruby::Types::AAAA, [])
0.upto([ipv4_addresses.length, ipv6_addresses.length].max - 1) do |idx|
tbl << [idx == 0 ? hostname : TABLE_INDENT, ipv4_addresses[idx], ipv6_addresses[idx]]
resolver.static_hostnames.sort_by { |hostname, _| hostname }.each do |hostname, addresses|
ipv4_addresses = addresses.fetch(Dnsruby::Types::A, []).sort_by(&:to_i)
ipv6_addresses = addresses.fetch(Dnsruby::Types::AAAA, []).sort_by(&:to_i)
if (ipv4_addresses.length <= 1 && ipv6_addresses.length <= 1) && ((ipv4_addresses + ipv6_addresses).length > 0)
tbl << [hostname, ipv4_addresses.first, ipv6_addresses.first]
else
tbl << [hostname, '', '']
0.upto([ipv4_addresses.length, ipv6_addresses.length].max - 1) do |idx|
tbl << [TABLE_INDENT, ipv4_addresses[idx], ipv6_addresses[idx]]
end
end
end
print_line(tbl.to_s)
Expand Down
2 changes: 1 addition & 1 deletion lib/rex/proto/dns/static_hostnames.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module DNS
class StaticHostnames
extend Forwardable

def_delegators :@hostnames, :each, :each_with_index, :length, :empty?
def_delegators :@hostnames, :each, :each_with_index, :length, :empty?, :sort_by

# @param [Hash<String, IPAddr>] hostnames The hostnames to IP address mappings to initialize with.
def initialize(hostnames: nil)
Expand Down

0 comments on commit 63b3ad2

Please sign in to comment.