11.04.2013 Views

Guida avanzata di scripting Bash - Portale Posta DMI

Guida avanzata di scripting Bash - Portale Posta DMI

Guida avanzata di scripting Bash - Portale Posta DMI

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

if [[ "$IPADDR" =~ "[(SERVFAIL)]$" ]]<br />

# Host xxxxxxxxx.xxx not found: 2(SERVFAIL)<br />

then<br />

echo "Host not found!"<br />

exit $E_NOHOST # Bail out.<br />

fi<br />

Appen<strong>di</strong>ce A. Script aggiuntivi<br />

# ======================== Main body of script ========================<br />

AFRINICquery() {<br />

# Define the function that queries AFRINIC. Echo a notification to the<br />

#+ screen, and then run the actual query, re<strong>di</strong>recting output to $OUTFILE.<br />

echo "Searching for $IPADDR in whois.afrinic.net"<br />

whois -h whois.afrinic.net "$IPADDR" > $OUTFILE<br />

# Check for presence of reference to an rwhois.<br />

# Warn about non-functional rwhois.infosat.net server<br />

#+ and attempt rwhois query.<br />

if grep -e "^remarks: .*rwhois\.[^ ]\+" "$OUTFILE"<br />

then<br />

echo " " >> $OUTFILE<br />

echo "***" >> $OUTFILE<br />

echo "***" >> $OUTFILE<br />

echo "Warning: rwhois.infosat.net was not working as of 2005/02/02" >> $OUTFILE<br />

echo " when this script was written." >> $OUTFILE<br />

echo "***" >> $OUTFILE<br />

echo "***" >> $OUTFILE<br />

echo " " >> $OUTFILE<br />

RWHOIS=‘grep "^remarks: .*rwhois\.[^ ]\+" "$OUTFILE" | tail -n 1 |\<br />

sed "s/\(^.*\)\(rwhois\..*\)\(:4.*\)/\2/"‘<br />

whois -h ${RWHOIS}:${PORT} "$IPADDR" >> $OUTFILE<br />

fi<br />

}<br />

APNICquery() {<br />

echo "Searching for $IPADDR in whois.apnic.net"<br />

whois -h whois.apnic.net "$IPADDR" > $OUTFILE<br />

# Just about every country has its own internet registrar.<br />

# I don’t normally bother consulting them, because the regional registry<br />

#+ usually supplies sufficient information.<br />

# There are a few exceptions, where the regional registry simply<br />

#+ refers to the national registry for <strong>di</strong>rect data.<br />

# These are Japan and South Korea in APNIC, and Brasil in LACNIC.<br />

# The following if statement checks $OUTFILE (whois.txt) for the presence<br />

#+ of "KR" (South Korea) or "JP" (Japan) in the country field.<br />

# If either is found, the query is re-run against the appropriate<br />

#+ national registry.<br />

713

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!