📄 ch12.htm
字号:
udp<BR>
108
z3950 wais
210
tcp<BR>
109
z3950 wais
210
udp<BR>
110
ipx 213
tcp<BR>
111
ipx 213
udp<BR>
112
imap3 220
tcp<BR>
113
imap3 220
udp<BR>
114
ulistserv 372
tcp<BR>
115
ulistserv 372
udp<BR>
116 exec 512
tcp<BR>
117 biff comsat
512
udp<BR>
118
login 513
tcp<BR>
119
who whod
513
udp<BR>
120
shell
cmd
514
tcp<BR>
121 syslog 514 &nbs
p;
udp<BR>
122 printer spooler
515
tcp<BR>
123 talk 517
udp<BR>
124
ntalk 518
udp<BR>
125
route router routed
520
udp<BR>
126
timed timeserver
525
udp<BR>
127
tempo newdate
526
tcp<BR>
128 courier
rpc
530
tcp<BR>
129 conference chat
531
tcp<BR>
130 netnews readnews
532
tcp<BR>
131 netwall 533 &nb
sp;
udp<BR>
132 uucp
uucpd
540
tcp<BR>
133 remotefs rfs_server
rfs
556
tcp<BR>
134 klogin 543 &nbs
p;
tcp<BR>
135 kshell 544 &nbs
p;
tcp<BR>
136 kerberos-adm 749 &nbs
p;
tcp<BR>
137 webster 765 &nb
sp;
tcp<BR>
138 webster 765 &nb
sp;
udp<BR>
139 ingreslock 1524  
;
tcp<BR>
140 ingreslock 1524  
;
udp<BR>
141
prospero-np 1525
tcp<BR>
142
prospero-np 1525
udp<BR>
143
rfe 5002
tcp<BR>
144
rfe 5002
udp<BR>
145 krbupdate kreg
760
tcp<BR>
146 kpasswd kpwd
761
tcp<BR>
147 eklogin 2105 &n
bsp;
tcp<BR>
148 supfilesrv 871
tcp<BR>
149 supfiledbg 1127  
;
tcp<BR>
</FONT></TT>
</BLOCKQUOTE>
<P>
<CENTER>
<TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%>
<TR VALIGN=TOP><TD ><B>Tip</B></TD></TR>
<TR VALIGN=TOP><TD >
<BLOCKQUOTE>
The <TT><FONT FACE="Courier">gethostent</FONT></TT> function was not implemented as of Perl 5.002.
</BLOCKQUOTE>
</TD></TR>
</TABLE></CENTER>
<P>
<P>
Perl also lets you look at the host name by address in your <TT><FONT FACE="Courier">/etc/hosts</FONT></TT>
file with the <TT><FONT FACE="Courier">gethostbyaddr</FONT></TT>
call. This function takes two parameters, the address to look
up and the value of <TT><FONT FACE="Courier">AF_INET</FONT></TT>.
On most systems, this value is set to <TT><FONT FACE="Courier">2</FONT></TT>
but can be looked up in the <TT><FONT FACE="Courier">/usr/include/sys/socket.h</FONT></TT>
file. The <TT><FONT FACE="Courier">gethostbyname("hostname")</FONT></TT>
function returns the same values as the <TT><FONT FACE="Courier">gethostbyaddr()</FONT></TT>
call. The parameter passed into the function is the name of the
host being looked up. Listing 12.3 illustrates how to do this.
<P>
In the program shown in Listing 12.3, the code in Line 4 gets
the host name and alias given the address <TT><FONT FACE="Courier">204.251.103.2</FONT></TT>.
You would use a different address, of course, because the address
shown here is specific to my machine. Lines 6 through 10 print
the components of the information you get back from the <TT><FONT FACE="Courier">gethostbyaddr</FONT></TT>
function call. Also, in lines 12 and 13, you can get the same
information back using the node name instead of an IP address.
Lines 14 through 19 print these values.
<HR>
<BLOCKQUOTE>
<B>Listing 12.3. Sample listing to show usage of </B><TT><B><FONT FACE="Courier">gethostbyname</FONT></B></TT><B>
and </B><TT><B><FONT FACE="Courier">gethostbyaddr</FONT></B></TT><B>.
<BR>
</B>
</BLOCKQUOTE>
<BLOCKQUOTE>
<TT><FONT FACE="Courier"> 1 #!/usr/bin/perl<BR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -