我复制了下面的脚本并运行它让它监听80端口。但是netstat
没有显示80端口。为什么不netstat
播,或者Perl脚本不正确?
#!/usr/bin/perl -w
use Socket;
use IO::Handle;
$port=80;
$host='localhost';
$packhost=inet_aton($host);
$address=sockaddr_in($port,$packhost);
socket(SERVER,AF_INET,SOCK_STREAM,getprotobyname('tcp'));
bind(SERVER,$address);
listen(SERVER,10);
while( 1 ) {
next unless (accept(CLIENT,SERVER));
CLIENT->autoflush(1);
$msg_out="WHAT DO YOU WANT?\n";
send(CLIENT,$msg_out,0);
close CLIENT;
}
close SERVER;
exit 1;