#!/usr/bin/perl use Socket; sub parseURL{ my ($url)=@_; return $url=~m/(https?):\/\/([^\/]*)(.*)/; } sub chunkDecode{ my ($chunkdata)=@_; my $chunk_header=0; my $unchunk=""; while(1){ if($chunk_header==0){ if($chunkdata=~/([0-9a-fA-F]+)[ \t]*\n/g){ $offset=pos($chunkdata); $chunksize=hex($1); if($chunksize==0){ goto end_of_chunk_data; } $unchunk.=substr($chunkdata,$offset,$chunksize); $chunkdata=substr($chunkdata,$offset+$chunksize); $chunkheader=1; }else{ goto end_of_chunk_data; } }else{ if($chunkdata=~/\n([0-9a-fA-F]+)[ \t]*\n/g){ $offset=pos($chunkdata); $chunksize=hex($1); if($chunksize==0){ goto end_of_chunk_data; } $unchunk.=substr($chunkdata,$offset,$chunksize); $chunkdata=substr($chunkdata,$offset+$chunksize); }else{ goto end_of_chunk_data; } } } end_of_chunk_data: return $unchunk; } $url="http://phpschool.com/zbbs/zboard.php?id=talkbox&page=1&sn1=&divpage=4&sn=off&ss=on&sc=on&select_arrange=headnum&desc=asc&no=22860"; ($protocol,$host,$uri)=parseURL($url); $port="80"; #create socket descriptor socket(SH,PF_INET,SOCK_STREAM,getprotobyname('tcp')) || die $!; #connecting to server my $sin=sockaddr_in($port,inet_aton($host)); connect(SH,$sin) || die $!; my $fh = select SH; $| = 1; select $fh; $body="GET ".$uri." HTTP/1.1\nConnection: close\nHost: ".$host."\n\n"; syswrite(SH,$body,length($body)); while(($len=sysread(SH,$read_buffer,256)>0)){ $content.=$read_buffer; } $content=~/\n\n/g; $offset=pos($content); $body=substr($content,$offset); print chunkDecode($body); close(SH);
Copyrights © - Joinc, All Rights Reserved. Inherited From - Yundream Rebranded By - Joonphil
설명
사용방법
코드
변경사항
2004/01/08
Recent Posts
Archive Posts
Tags