Simple Bash Script for obtaining IP addresses verse computer names

Situation: User gave me computer names but I need the ip addresses for over 300 machines so I can scan them.

Finished result below
*******************************
#!/bin/bash
var="-c 1"
for i in $(cat domainnames.txt | awk '{print $1}'); do ping=$(ping $i $var | grep data | awk '{print $3}' | sed s/"("/""/ | sed s/")"/""/ |sed s/":"/""/ >> ipsout.txt);done;
**************************************************
Explanation Below

The -c 1 gets you a single ping when running in a linux environment or from cygwin in windows.

I am typing the domain names (domainnames.txt) which were giving in name form. After a single ping it provides name.domainname.com.

I started out by pinging an address
ping server1 -c 1
First line reports with
PING server1.domainname.com (10.20.2.238): 0 data bytes
8 bytes from 10.20.2.238: icmp_seq=0 ttl=125

So I count over the places and (10.20.2.238): is the third place so now I type:

ping server1 -c 1 | grep data | awk '{print $3 " " }'
(10.20.2.238):

I grep data because its unique to the line 1. I grab out the third place holder and you see the result above. Now we need to get rid of the parenthesis and the colon.

ping server1 -c 1 | grep data | awk '{print $3 " " }' | sed s/"("/""/ | sed s/")"/""/ |sed s/":"/""/

This is where I use sed to remove what I do not what. Lets see the output.
ping server1 -c 1 | grep data | awk '{print $3 " " }' | sed s/"("/""/ | sed s/")"/""/ |sed s/":"/""/
10.20.2.238

Excellent now we have an ip in the format we want. Now lets create the for loop which is the code from above.

#!/bin/bash
var="-c 1"
for i in $(cat domainnames.txt | awk '{print $1}'); do ping=$(ping $i $var | grep data | awk '{print $3}' | sed s/"("/""/ | sed s/")"/""/ |sed s/":"/""/ >> ipsout.txt);done;

I am reading in the domainnames.txt and since I had other data in the file I am printing only the domain name with the awk '{print $1}'); command. You do not need to do this unless your file contains other information. I don't really need the ping variable but I thought I might for some other scripts anyhow I now call each line with just the ip with the $1 and use the $var for only 1 ping. Now the rest is everything I explained above.

Now I can upload ipsout.txt into Nessus and scan my ips.

Enjoy