Batch Checking Domain Nameservers for WordPress Multisite

Migrating a WordPress multisite from one host to another can be quite the undertaking. Especially if you are using domain mapping you have many domains to update with IP addresses.

You may have forgotten where some of the domains are registered so this script will help. First we list the domains used in the multisite and trim out the http:// and https:// schemes. Then we use the program dig on Linux to check the name servers.

You can get a list of your domains using WP-CLI and then trim them with sed to get rid of the http scheme.

wp site list --field=url --allow-root | sed -E "s#https?://##g" | tr -d '/'

Your output will then be a nice clean list of the domains in your multisite using domain mapping

thirteenthfloor.com
zombieapocalypselive.com
greatroomescape.com
valentineshauntedhouses.com
massivenoise.com
slasherfest.com
hauntedattraction.com
denverzombiecrawl.com
tophauntreview.com
krampushauntedchristmas.com
glowpumpkin.com

We can also use sed exclusively

wp site list --allow-root --field=url | sed -E "s#https?://(.*)/#\1#g"

Now we need to use dig to check the nameservers for the domain. You can install dig on Ubuntu/Debian systems like this

sudo apt update
sudo apt install dnsutils -y

Now you can check the nameservers for a domain like this

dig domain.com NS +short

You will get output like this listing the nameservers

ns75.domaincontrol.com.
ns76.domaincontrol.com.

Now we can put it together in a script that loops through the domains and runs the dig command for each domain.

#!/usr/bin/env bash
# array of domains
DOMAINS=(
thirteenthfloor.com
zombieapocalypselive.com
greatroomescape.com
valentineshauntedhouses.com
massivenoise.com
slasherfest.com
hauntedattraction.com
denverzombiecrawl.com
tophauntreview.com
krampushauntedchristmas.com
glowpumpkin.com)

for DOMAIN in ${DOMAINS[@]};
do
    echo -e "Checking ${DOMAIN}"
    dig ${DOMAIN} NS +short
done

Output

Checking thirteenthfloor.com
ns7598168164.a2dns.com.
ns7598168165.a2dns.com.
Checking zombieapocalypselive.com
ns54.domaincontrol.com.
ns53.domaincontrol.com.
Checking greatroomescape.com
ns38.domaincontrol.com.
ns37.domaincontrol.com.
Checking valentineshauntedhouses.com
ns47.domaincontrol.com.
ns48.domaincontrol.com.
Checking massivenoise.com
ns1.domainhasexpired.com.
ns2.domainhasexpired.com.
Checking slasherfest.com
ns72.domaincontrol.com.
ns71.domaincontrol.com.
Checking hauntedattraction.com
ns13.domaincontrol.com.
ns14.domaincontrol.com.
Checking denverzombiecrawl.com
ns40.domaincontrol.com.
ns39.domaincontrol.com.
Checking tophauntreview.com
ns76.domaincontrol.com.
ns75.domaincontrol.com.
Checking krampushauntedchristmas.com
ns59.domaincontrol.com.
ns60.domaincontrol.com.
Checking glowpumpkin.com
ns40.domaincontrol.com.
ns39.domaincontrol.com.