Simple script to get the IP of a list of hostnames (update)

December 18, 2017 - Reading time: ~1 minute

I made a file called to_find_ip which has a hostname on every line. And a simple bash script to process the file and return the matching IP.

The script called (use getent ahosts if you only need IPv4 addresses)

while read p; do
getent hosts $p | cut -f1 -d ' '
done <$1

To run the script:

sh /tmp/ /tmp/to_find_ip


Koen Diels

I'm a freelance system and network engineer from Mechelen (BE) and I'm available for ad-hoc and long term projects.

>>my resume<<