From 8bf896a90848e0753e08d2a1291cbad87451c8c0 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 2 Feb 2024 00:55:45 +0200 Subject: [PATCH] 1 --- dump-dns-cache.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++ replace-str.rb | 5 +++++ 2 files changed, 50 insertions(+) create mode 100755 dump-dns-cache.sh create mode 100755 replace-str.rb diff --git a/dump-dns-cache.sh b/dump-dns-cache.sh new file mode 100755 index 0000000..a0fbee9 --- /dev/null +++ b/dump-dns-cache.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash + +HOST="$1" +USERNAME="$2" +PASSWORD="$3" +FILTER="$4" +USE_RUBY="0" + +if [ -z "${HOST}" ] +then + echo "Missing hostname" + exit 1 +fi + +if [ -z "${USERNAME}" ] +then + echo "Missing username" + exit 1 +fi + +if [ -z "${PASSWORD}" ] +then + echo "Missing password" + exit 1 +fi + +if [ -z "${FILTER}" ] +then + JQ_QUERY_TEMPLATE='.[]' +else + JQ_QUERY_TEMPLATE='.[] | select(.name|contains("###PATTERN###"))' +fi + +QUERY='{".proplist": [".id","name","type","data","ttl"]}' + +if [ "${USE_RUBY}" -gt "0" ] +then + JQ_QUERY=$( echo "${JQ_QUERY_TEMPLATE}" |ruby replace-str.rb "###PATTERN###" "${FILTER}" ) +else + JQ_QUERY=$( echo "${JQ_QUERY_TEMPLATE}" | sed -e "s@###PATTERN###@${FILTER}@g" ) +fi + +curl -s -k -u "${USERNAME}:${PASSWORD}" "https://${HOST}/rest/ip/dns/cache/print" \ + --data "${QUERY}" -H "content-type: application/json" | \ + jq "${JQ_QUERY}" diff --git a/replace-str.rb b/replace-str.rb new file mode 100755 index 0000000..cbae541 --- /dev/null +++ b/replace-str.rb @@ -0,0 +1,5 @@ +#!/usr/bin/env ruby + +while line = STDIN.gets + puts "#{line.chomp.gsub("#{ARGV[0]}","#{ARGV[1]}")}" +end