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.

}<br />

if grep -E "^country:[ ]+KR$" "$OUTFILE"<br />

then<br />

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

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

elif grep -E "^country:[ ]+JP$" "$OUTFILE"<br />

then<br />

echo "Searching for $IPADDR in whois.nic.ad.jp"<br />

whois -h whois.nic.ad.jp "$IPADDR"/e >> $OUTFILE<br />

fi<br />

ARINquery() {<br />

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

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

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

# Several large internet providers listed by ARIN have their own<br />

#+ internal whois service, referred to as "rwhois".<br />

# A large block of IP addresses is listed with the provider<br />

#+ under the ARIN registry.<br />

# To get the IP addresses of 2nd-level ISPs or other large customers,<br />

#+ one has to refer to the rwhois server on port 4321.<br />

# I originally started with a bunch of "if" statements checking for<br />

#+ the larger providers.<br />

# This approach is unwieldy, and there’s always another rwhois server<br />

#+ that I <strong>di</strong>dn’t know about.<br />

# A more elegant approach is to check $OUTFILE for a reference<br />

#+ to a whois server, parse that server name out of the comment section,<br />

#+ and re-run the query against the appropriate rwhois server.<br />

# The parsing looks a bit ugly, with a long continued line inside<br />

#+ backticks.<br />

# But it only has to be done once, and will work as new servers are added.<br />

#@ ABS Guide author comment: it isn’t all that ugly, and is, in fact,<br />

#@+ an instructive use of Regular Expressions.<br />

}<br />

if grep -E "^Comment: .*rwhois.[^ ]+" "$OUTFILE"<br />

then<br />

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

sed "s/^\(.*\)\(rwhois\.[^ ]\+\)\(.*$\)/\2/"‘<br />

echo "Searching for $IPADDR in ${RWHOIS}"<br />

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

fi<br />

LACNICquery() {<br />

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

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

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

#+ "BR" (Brasil) in the country field.<br />

# If it is found, the query is re-run against whois.registro.br.<br />

if grep -E "^country:[ ]+BR$" "$OUTFILE"<br />

then<br />

714

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

Saved successfully!

Ooh no, something went wrong!