用perl实现http服务-用来传文件
发布时间:2020-12-15 20:59:15 所属栏目:大数据 来源:网络整理
导读:#!/usr/bin/perl -wuse IO::Socket;my $a=IO::Socket::INET-new(LocalPort=8888,Listen=1,ReuseAddr=1);*OUT=*STDOUT;while($b=$a-accept()){$b-recv(my $buf,1024,0);$file=$1 if($buf=~/GETs+(S+)/m);print OUT $buf;select $b;$|=1;$file=q(/tftp/) . $
#!/usr/bin/perl -w use IO::Socket; my $a=IO::Socket::INET->new(LocalPort=>8888,Listen=>1,ReuseAddr=>1); *OUT=*STDOUT; while($b=$a->accept()) { $b->recv(my $buf,1024,0); $file=$1 if($buf=~/GETs+(S+)/m); print OUT $buf; select $b; $|=1; $file=q(/tftp/) . $file; $len = -s $file; print <<AAA HTTP/1.1 200 OK Date: Sun,04 Mar 2012 02:04:14 GMT Server: Apache/2.2.20 (Ubuntu) Last-Modified: Thu,01 Mar 2012 09:08:44 GMT ETag: "38308e-500000000-4ba2ace9a2538" Accept-Ranges: bytes Content-Length: $len Connection: close Content-Type: text/plain AAA ; open(F,$file); while(<F>) { print ; } close F; close $b; } close $a; 将 此代码写成一个http.pl,在/tftp目录下,使用perl http.pl 即可打开http服务。 此时 通过客户端就可以在浏览器输入 172.16.14.3:8888/vmlinux 即可通过http协议下载文件 在 pmon中可以用load http://172.16.14.3:8888/vmlinux即可向内存中load文件。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |