Read Hostname and Return IP Address


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Read Hostname and Return IP Address
# 1  
Old 11-15-2008
Read Hostname and Return IP Address

Dear Experts,

I have a text file on my itanium box which contains list of nearly 1000 hostnames. I do not have the IP Address of them. I want read each entry from the text file and want to do a nslookup to the DNS Server and get the IP Adresses and put them in another file in the format hostname IP Address.

Lets say,

I have abcd.server.com in my text file first line. I want a script which reads this entry and gets the IP Address from DNS and paste in another file as

abcd.server.com 1.1.1.1

the script should then read the next entry in the text file and go until the end of the file and exit.


Thanks in Advance
# 2  
Old 11-15-2008

Assuming that the output of your version of nslookup is similar to those I have access to:

Code:
while read host
do
  lookup=${nslookup "$host"}
  printf "%s %s\n" "$host" "${lookup##*Address: }"
done < FILENAME > NEWFILE

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

SMTP relay one (1) hostname with two (2) IP Address

Hi, Anyone can help? Currently : I'm am using a smtp smart relay, 1 hostname but different IP Address 192.168.2.108 and 192.168.2.109). I'm using "smtp.mailhostname.com mailhost" and having an IP Address 192.168.2.108, but there is a certain minutes/seconds that the IP Address will... (2 Replies)
Discussion started by: fspalero
2 Replies

2. AIX

Mutt from address and hostname

Mutt 1.2.3.1i AIX 5.3.12.1 We need to send email to external addresses. But are having problems with the sent-from hostname. They're going out with @server.mycompany.com. We need them to be @mycompany.com. I'm setting from and hostname with -e 'set from="From... (1 Reply)
Discussion started by: Papa Lee
1 Replies

3. UNIX for Dummies Questions & Answers

Solaris - How to get IP Address from a hostname?

We are using Solaris as our database OS. Can you please help me to know how can i get the IP address of a solaris machine in my network from its hostname? e.g. We have a remote database server with the hostname as xyz. Without connecting to the database OS, can i get the IP address of xyz OS from... (1 Reply)
Discussion started by: Anmol Sharma
1 Replies

4. UNIX for Dummies Questions & Answers

Routing or Iptables connections by hostname or ip address

edit; I found a solution that works, see thread #3 https://www.unix.com/302417065-post3.html Hi there, I have a small dedicated server that has four ip addresses and by default my httpd sends request using the servers main ip for all outbound connections. I'm quite amateur at routing and... (4 Replies)
Discussion started by: mooofa
4 Replies

5. Shell Programming and Scripting

Convert IP address (within a line) to hostname

I have a tricky problem, and I'm quite the scripting newb. I have Cisco ACLs that have IP addresses in them. I'd like to convert the IP's to hostnames for easier analysis. A sample ACL input file would be (I've obfuscated the IPs): access-list acl-secure-out line 1 extended permit icmp any... (3 Replies)
Discussion started by: scolazz
3 Replies

6. Shell Programming and Scripting

Validate an IP address - Return to menu

hi! I need a script that, among other things, presents a menu to the user, checks the user input for an IP address (in quad dotted notation), and then "redirects" (with sed) that IP address to the Firewall script. The script must check that all of the inputs are valid IP addresses (numeric,... (1 Reply)
Discussion started by: zetetic
1 Replies

7. UNIX for Dummies Questions & Answers

return IP address

Hi, If my IP address is 192.29.0.131 I want output _0_131 # /sbin/ifconfig | grep "inet addr" | grep 192 | cut -d "." -f3 0 I have tried the above and I get third digit. I want forth digit as well separated by underscore. Or is there any better approach? (4 Replies)
Discussion started by: shantanuo
4 Replies

8. UNIX for Dummies Questions & Answers

IP address/hostname problem

I have a problem that when I am pinging with the IP address it is giving me whether a server is alive or not but when I am trying it with hostname it is giving unknown host I have checked in /etc/hosts file and the IP address and hostname are both there...still the problem is there.. Can... (1 Reply)
Discussion started by: uLearner
1 Replies

9. Programming

Return IP address

Not sure whether this is an appropriate request, however, Using C++ code I'm running a unix command from the pc that needs the IP address of the PC in order to set the DISPLAY variable. The code is written using Builder C++ (Borland) but I'm having difficulty finding what functions / header... (3 Replies)
Discussion started by: gefa
3 Replies

10. IP Networking

pine username return address

hello all I am happily using pine but unhappily sending email as username@where.my.mail.works instead of ****@my.college.edu well, my username on my computer is one thing, but my username on my college account (**** here) is different. what I'm trying to do is use the college server for... (1 Reply)
Discussion started by: plusran
1 Replies
Login or Register to Ask a Question