Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

bash script to resolve all hostnames in a list

Posted on 2016-07-31
8
Medium Priority
?
91 Views
Last Modified: 2016-07-31
Hi Guys,
I have a list of over 100 domains.
I need to get the A record of each one of them through a bash script.
I also need the same bash script to write the resolve next to FQDN itself...
Meaning, before the script:
cat /home/user/domains.list

Open in new window

will return
google.com
amazon.com

and after the script it will return
google.com 216.52.217.78
amazon.com 54.239.25.200
0
Comment
Question by:David Sankovsky
  • 5
  • 3
8 Comments
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 41736239
I'm curious what you are going to do with them.  I ask because your two examples, google.com and amazon.com have not just one but many IP addresses.
0
 
LVL 7

Author Comment

by:David Sankovsky
ID: 41736243
You are correct Dave but they are only examples. in my scenario I know for a fact that no one will have more than one resolve, I do however expect some to return nxdomain.

The point is simple I have a plesk server we wish to close that has over 100 FQDNs. We want to close this server, we just need to know which domains still actually point to this server.
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 41736246
Interesting.  I would have thought that the Plesk software would tell you that.  Or do you know that some have moved to other servers already?
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 41736252
I just wrote a PHP script that does the lookup for my own websites.  I can post that if you want.
0
 
LVL 7

Author Comment

by:David Sankovsky
ID: 41736262
Might even be better I could integrate that into one of my management sites...
0
 
LVL 84

Accepted Solution

by:
Dave Baldwin earned 2000 total points
ID: 41736669
This just displays the name and IP, one to a row.  Substitute you domain names but make sure and observe the punctuation.   You could collect them into a variable and save it to a file fairly easily.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>gethostbyname</title>
</head>
<body>
<?php
$hostz = array(
	"www.Yoursite.com"
	, "www.Yoursite.org"
	, "www.Yoursite.net"
	, "www.Yoursite.info"
	);

foreach($hostz as $value) {
	echo $value." = ";
	$ip = gethostbyname($value);
	echo $ip."<br>";
	}
?>
</body>
</html>

Open in new window

0
 
LVL 7

Author Comment

by:David Sankovsky
ID: 41737004
ok, now I just need to make that read from a file.
Thanks a lot :)
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 41737010
You're welcome, glad to help.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month7 days, 11 hours left to enroll

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question