[Tutor] Finding Hostname-IP DNS mappings and if machine is dead or alive
KIRAN D.S.
kirands at yahoo.com
Mon May 12 23:44:14 CEST 2014
Hi,
I have a UNIX shell script that:
a. lists out the Hostname-IP DNS mappings
b. checks whether the machine is pingable, and prints "dead" or "alive" depending on status.
I want to write this program in Python but am struggling. Can someone help please ?
Here's my script and output run
===============================
(I have changed my company name to "company", and machine names for privacy reasons)
pqr49: / >
pqr49: / > cat 72-network-IP-DNS-checker
#!/bin/bash
i=1
while [ $i -lt 255 ]; do
hostip=10.145.72.$i
echo -n "$hostip "
hn=None
host $hostip > /dev/null 2>&1
if [ "$?" -ne 0 ]; then
echo -n NoDNS
else
echo -n DNS
hn=`host $hostip | awk '{print $NF}'`
fi
ping $hostip 1 > /dev/null 2>&1
if [ "$?" -eq 0 ]; then
echo -n " alive "
else
echo -n " dead "
fi
echo $hn
i=`expr $i + 1`
done
exit
pqr49: / >
pqr49: / > ./72-network-IP-DNS-checker
10.145.72.1 DNS alive piedmont22-1257-rtr-1-v3007.us.company.com.
10.145.72.2 NoDNS dead None
10.145.72.3 NoDNS dead None
10.145.72.4 NoDNS dead None
10.145.72.5 NoDNS alive None
10.145.72.6 DNS dead golf9999-nwk1k.us.company.com.
10.145.72.7 DNS alive golf9999-nwk2a.us.company.com.
10.145.72.8 DNS alive golf9999-nwk2c.us.company.com.
10.145.72.9 NoDNS dead None
10.145.72.10 DNS alive pqr585.us.company.com.
10.145.72.11 DNS alive pqr585-sp.us.company.com.
10.145.72.12 DNS alive pqr585-2540-1.us.company.com.
10.145.72.13 DNS alive pqr585-2540-2.us.company.com.
10.145.72.14 DNS alive xyz-efgh101.us.company.com.
10.145.72.15 DNS alive xyz-efgh101-pqrst.us.company.com.
10.145.72.16 DNS alive xyz-efgh102.us.company.com.
10.145.72.17 DNS alive xyz-efgh102-pqrst.us.company.com.
10.145.72.18 DNS alive xyz-def-ib102.us.company.com.
10.145.72.19 DNS dead pqr294-sp.us.company.com.
10.145.72.20 DNS alive pqr582.us.company.com.
10.145.72.21 DNS alive pqr582-sp.us.company.com.
10.145.72.22 DNS alive pqr580.us.company.com.
10.145.72.23 DNS alive pqr580-sp.us.company.com.
10.145.72.24 DNS alive pqr550.us.company.com.
10.145.72.25 DNS dead pqr551.us.company.com.
10.145.72.26 DNS alive pqr551-sp.us.company.com.
10.145.72.27 DNS^C
pqr49: / >
pqr49: / >
Thank you and regards,
Kiran
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140512/d740dc53/attachment-0001.html>
More information about the Tutor
mailing list