Some of this might seem more complicated than it should be. So when you’re running a script you might choose to grab DNS information one way or another, according to what you’re after.
There are a number of ways to grab what DNS server a device is using in macOS.
For example, something as simple as what hosts you use to resolve names on a Mac. One of my favorite things about grabbing things with scripts is just how many ways (and sometimes how needfully or needlessly convoluted you can make them) to grab the same pieces of information.