From 8a186d252bf848dcbfac2c6de39b2c5b635c0889 Mon Sep 17 00:00:00 2001 From: borekon Date: Thu, 27 Oct 2022 11:19:59 +0000 Subject: [PATCH] =?UTF-8?q?A=C3=B1adir=20'ip2host.sh'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ip2host.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 ip2host.sh diff --git a/ip2host.sh b/ip2host.sh new file mode 100644 index 0000000..579e7b2 --- /dev/null +++ b/ip2host.sh @@ -0,0 +1,22 @@ +#!/bin/bash +if [ -z "$1" ] +then + echo "You must specify a filename to read from" + exit 1; +fi +if [ ! -f "$1" ] +then + echo "File $1 does not exist or is not a file" + exit 1; +fi +while read ip n +do + # Uncomment following to use /etc/hosts + # name=$(awk -v ip=$ip '$1 ~ ip{print $2}' /etc/hosts) + # Uncomment following to use nslookup + # name=$(nslookup $ip| grep "name ="|sed 's/.*=//') + # Uncomment following line to use dig (thanks to Charles Duffy) + #name=$(dig +short -x $ip)i + resolvedIP=$(dig +short -x "$ip") + [[ -z "$resolvedIP" ]] && echo "$ip" lookup failure || echo "$ip" resolved to "$resolvedIP" +done < $1