⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch18_09.htm

📁 By Tom Christiansen and Nathan Torkington ISBN 1-56592-243-3 First Edition, published August 1998
💻 HTM
字号:
<HTML><HEAD><TITLE>Recipe 18.8. Using Whois to Retrieve Information from the InterNIC (Perl Cookbook)</TITLE><METANAME="DC.title"CONTENT="Perl Cookbook"><METANAME="DC.creator"CONTENT="Tom Christiansen &amp; Nathan Torkington"><METANAME="DC.publisher"CONTENT="O'Reilly &amp; Associates, Inc."><METANAME="DC.date"CONTENT="1999-07-02T01:45:07Z"><METANAME="DC.type"CONTENT="Text.Monograph"><METANAME="DC.format"CONTENT="text/html"SCHEME="MIME"><METANAME="DC.source"CONTENT="1-56592-243-3"SCHEME="ISBN"><METANAME="DC.language"CONTENT="en-US"><METANAME="generator"CONTENT="Jade 1.1/O'Reilly DocBook 3.0 to HTML 4.0"><LINKREV="made"HREF="mailto:online-books@oreilly.com"TITLE="Online Books Comments"><LINKREL="up"HREF="ch18_01.htm"TITLE="18. Internet Services"><LINKREL="prev"HREF="ch18_08.htm"TITLE="18.7. Pinging a Machine"><LINKREL="next"HREF="ch18_10.htm"TITLE="18.9. Program: expn and vrfy"></HEAD><BODYBGCOLOR="#FFFFFF"><img alt="Book Home" border="0" src="gifs/smbanner.gif" usemap="#banner-map" /><map name="banner-map"><area shape="rect" coords="1,-2,616,66" href="index.htm" alt="Perl Cookbook"><area shape="rect" coords="629,-11,726,25" href="jobjects/fsearch.htm" alt="Search this book" /></map><div class="navbar"><p><TABLEWIDTH="684"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="228"><ACLASS="sect1"HREF="ch18_08.htm"TITLE="18.7. Pinging a Machine"><IMGSRC="../gifs/txtpreva.gif"ALT="Previous: 18.7. Pinging a Machine"BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="228"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1"><ACLASS="chapter"REL="up"HREF="ch18_01.htm"TITLE="18. Internet Services"></A></FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="228"><ACLASS="sect1"HREF="ch18_10.htm"TITLE="18.9. Program: expn and vrfy"><IMGSRC="../gifs/txtnexta.gif"ALT="Next: 18.9. Program: expn and vrfy"BORDER="0"></A></TD></TR></TABLE></DIV><DIVCLASS="sect1"><H2CLASS="sect1"><ACLASS="title"NAME="ch18-chap18_using_0">18.8. Using Whois to Retrieve Information from the InterNIC</A></H2><DIVCLASS="sect2"><H3CLASS="sect2"><ACLASS="title"NAME="ch18-pgfId-995">Problem<ACLASS="indexterm"NAME="ch18-idx-1000004329-0"></A><ACLASS="indexterm"NAME="ch18-idx-1000004329-1"></A><ACLASS="indexterm"NAME="ch18-idx-1000004329-2"></A><ACLASS="indexterm"NAME="ch18-idx-1000004329-3"></A></A></H3><PCLASS="para">You want to find out who owns a domain, as if you'd used the Unix <CODECLASS="literal">whois</CODE> command.</P></DIV><DIVCLASS="sect2"><H3CLASS="sect2"><ACLASS="title"NAME="ch18-pgfId-1001">Solution</A></H3><PCLASS="para">Use the CPAN module Net::Whois:</P><PRECLASS="programlisting">use Net::Whois;$domain_obj = Net::Whois::Domain-&gt;new($domain_name)    or die &quot;Couldn't get information on $domain_name: $!\n&quot;;# call methods on $domain_obj to get name, tag, address, etc.</PRE></DIV><DIVCLASS="sect2"><H3CLASS="sect2"><ACLASS="title"NAME="ch18-pgfId-1019">Discussion</A></H3><PCLASS="para">Whois is a service provided by domain name registration authorities to identify owners of domain names. Historically, queries were made with the <ICLASS="filename">whois </I>(1) program on Unix systems, which returned about fifteen lines of information, including the names, addresses, and phone numbers of the administrative, technical, and billing contacts for the domain.</P><PCLASS="para">The <CODECLASS="literal">Net::Whois</CODE> module is a client for the whois service, just like <ICLASS="filename">whois</I> (1). It connects to a whois server (the default is <CODECLASS="literal">whois.internic.net</CODE>, the master server for the <CODECLASS="literal">&quot;.com&quot;</CODE>, <CODECLASS="literal">&quot;.org&quot;</CODE>, <CODECLASS="literal">&quot;.net&quot;</CODE>, and <CODECLASS="literal">&quot;.edu&quot;</CODE> domains) and gives you access to the information through method calls on an object.</P><PCLASS="para">To request information on a domain, create a new Net::Whois::Domain object. For instance, to look up information on <CODECLASS="literal">perl.org</CODE>:</P><PRECLASS="programlisting">$d = Net::Whois::Domain-&gt;new( &quot;perl.org&quot; )    or die &quot;Can't get information on perl.org\n&quot;;</PRE><PCLASS="para">The only guaranteed fields are the domain name and the tag &nbsp;-  the domain's unique identifier in the NIC records:</P><PRECLASS="programlisting">print &quot;The domain is called &quot;, $d-&gt;domain, &quot;\n&quot;;print &quot;Its tag is &quot;, $d-&gt;tag, &quot;\n&quot;;</PRE><PCLASS="para">Information that may be present includes: <EMCLASS="emphasis">name</EM> of the domain's company or product (e.g., &quot;<CODECLASS="literal">The</CODE> <CODECLASS="literal">Perl</CODE> <CODECLASS="literal">Institute</CODE>&quot;), the <EMCLASS="emphasis">address</EM> of the company (a list of lines, e.g., <CODECLASS="literal">(&quot;221B</CODE> <CODECLASS="literal">Baker</CODE> <CODECLASS="literal">Street&quot;,</CODE> <CODECLASS="literal">&quot;London&quot;)</CODE>), and the <EMCLASS="emphasis">country</EM> the address is valid for (e.g., &quot;<CODECLASS="literal">United</CODE> <CODECLASS="literal">Kingdom</CODE>&quot; or its two-letter abbreviation &quot;<CODECLASS="literal">uk</CODE>&quot;).</P><PRECLASS="programlisting">print &quot;Mail for &quot;, $d-&gt;name, &quot; should be sent to:\n&quot;;print map { &quot;\t$_\n&quot; } $d-&gt;address;print &quot;\t&quot;, $d-&gt;country, &quot;\n&quot;;</PRE><PCLASS="para">In addition to information about the domain, you can also get information on the domain's <EMCLASS="emphasis">contacts</EM>. The <CODECLASS="literal">contact</CODE> method returns a reference to a hash mapping contact type (e.g., <CODECLASS="literal">&quot;Billing&quot;</CODE> or <CODECLASS="literal">&quot;Administrative&quot;</CODE>) onto an array of lines.</P><PRECLASS="programlisting">$contact_hash = $d-&gt;contacts;if ($contact_hash) {    print &quot;Contacts:\n&quot;;    foreach $type (sort keys %$contact_hash) {        print &quot;  $type:\n&quot;;        foreach $line (@{$contact_hash-&gt;{$type}}) {            print &quot;    $line\n&quot;;        }    }} else {    print &quot;No contact information.\n&quot;;}<ACLASS="indexterm"NAME="ch18-idx-1000004331-0"></A><ACLASS="indexterm"NAME="ch18-idx-1000004331-1"></A><ACLASS="indexterm"NAME="ch18-idx-1000004331-2"></A><ACLASS="indexterm"NAME="ch18-idx-1000004331-3"></A></PRE></DIV><DIVCLASS="sect2"><H3CLASS="sect2"><ACLASS="title"NAME="ch18-pgfId-1073">See Also</A></H3><PCLASS="para">The documentation for the Net::Whois module from CPAN; your system's <ICLASS="filename">whois </I>(8) manpage (if you have one); RFC 812 and 954</P></DIV></DIV><DIVCLASS="htmlnav"><P></P><HRALIGN="LEFT"WIDTH="684"TITLE="footer"><TABLEWIDTH="684"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="228"><ACLASS="sect1"HREF="ch18_08.htm"TITLE="18.7. Pinging a Machine"><IMGSRC="../gifs/txtpreva.gif"ALT="Previous: 18.7. Pinging a Machine"BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="228"><ACLASS="book"HREF="index.htm"TITLE="Perl Cookbook"><IMGSRC="../gifs/txthome.gif"ALT="Perl Cookbook"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="228"><ACLASS="sect1"HREF="ch18_10.htm"TITLE="18.9. Program: expn and vrfy"><IMGSRC="../gifs/txtnexta.gif"ALT="Next: 18.9. Program: expn and vrfy"BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="228">18.7. Pinging a Machine</TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="228"><ACLASS="index"HREF="index/index.htm"TITLE="Book Index"><IMGSRC="../gifs/index.gif"ALT="Book Index"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="228">18.9. Program: expn and vrfy</TD></TR></TABLE><HRALIGN="LEFT"WIDTH="684"TITLE="footer"><FONTSIZE="-1"></DIV<!-- LIBRARY NAV BAR --> <img src="../gifs/smnavbar.gif" usemap="#library-map" border="0" alt="Library Navigation Links"><p> <a href="copyrght.htm">Copyright &copy; 2002</a> O'Reilly &amp; Associates. All rights reserved.</font> </p> <map name="library-map"> <area shape="rect" coords="1,0,85,94" href="../index.htm"><area shape="rect" coords="86,1,178,103" href="../lwp/index.htm"><area shape="rect" coords="180,0,265,103" href="../lperl/index.htm"><area shape="rect" coords="267,0,353,105" href="../perlnut/index.htm"><area shape="rect" coords="354,1,446,115" href="../prog/index.htm"><area shape="rect" coords="448,0,526,132" href="../tk/index.htm"><area shape="rect" coords="528,1,615,119" href="../cookbook/index.htm"><area shape="rect" coords="617,0,690,135" href="../pxml/index.htm"></map> </BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -