Bash script to get result of nslookup against several DNS servers?
Hello
I want to do a nslookup of a FQDN. First Ill try it against my local DNS server. If that doesnt work, Ill have a text file with several DNS servers (Google, Cloudflare, etc) and try to nslookup against those. If one DNS server doesnt give a reply the next, and etc....The first one that gives a reply, I want to save the IP in a variable. How can I do this? |
Is this a Linux Newbie question, a Networking question, or a General question?
It seems as if you have a process: Quote:
Quote:
If you have a series of commands which work for you, please share those, and would be happy to offer ways to adjust the output so that you can use parts of it as variables within your script, as well as help you code some series of commands into a script. I'm just no expert at exactly the content which you want, therefore do not wish to provide the commands in place of your expertise for that. |
Quote:
Code:
$servertrying="gosdfsdfogle.com" |
Well I don't know powershell. That stuff looks like Java or CPP with the try-catch statements.
Is Resolve-DnsName an available command on your system? Appears as if you can just issue that statement (along with the variable set): Code:
servertrying="gosdfsdfogle.com" What I'm saying is that you can take the $ off of those at the start of the line, copy and past those lines: servertrying="gosdfsdfogle.com" ip=Resolve-DnsName -Name $servertrying -Server 1.1.1.1 -Type A | Select -ExpandProperty IPAddress -ErrorAction Stop <or any of the ip= commands) into your command prompt and you will be able to inspect the results: Code:
$ echo $servertrying Or is there a problem writing bash scripts? If so, the link in my signature citing My Bash Blog is for debugging bash scripts, but also contains links to the Bash Script guide to get you started with bash scripting in general. Another starting point is: Code:
#!/bin/bash |
You might try using dig
Code:
dig +short @1.1.1.1 @8.8.8.8 gosdfsdfogle.com A Code:
dig Code:
man dig |
All times are GMT -5. The time now is 03:17 AM. |