Check HTTP status code for a page on all DNS records

09-04-2017 | Remy van Elst

Table of Contents

This is a small snippet using curl to check the status code of a given URL on all DNS records for a given domain. This site has a few A records in round robin mode, and sometimes the automatic deployment fails. Using this query I can check which server is the culprit and fix it manually.

If you like this article, consider sponsoring me by trying out a Digital Ocean VPS. With this link you'll get a $5 VPS for 2 months free (as in, you get $10 credit). (referral link)

The normal HEAD request output also shows all the headers the server sends and that is a pain to scroll through. This just shows me the HTTP status code, which is all I want.

dig +short A | awk '{print "echo "$1"; curl -s -k -o /dev/null -I -w \"%{http_code}\" https://"$1"/s/blog/Burn_in_testing_for_Hypervisor_and_Storage_servers.html; echo; echo"}' | bash

Example output:

The first and last server are correct. The middle one with status code 000 is offline and the 404 code is also not up to date.

For IPv6 and AAAA records, we add brackets:

dig +short AAAA | awk '{print "echo "$1"; curl -6 -s -k -o /dev/null -I -w \"%{http_code}\" https://["$1"]/s/blog/Burn_in_testing_for_Hypervisor_and_Storage_servers.html; echo; echo"}' | bash

Example output:



Tags: bash,curl,dns,