如何像httplook一样抓取http的包? ( 积分: 50 )

  • 主题发起人 主题发起人 macrolen
  • 开始时间 开始时间
抓 TCP 包 监听80端口则是发送
 
httplook :hook IE,
 
使用idhttp控件就可以了.在它的Response.ResponseText属性里查找
 
Trim(Copy(s, Pos('Host:', s) + 1, Pos('Connection:', s) -1 ));
要不用政则表达式分析。
 
之前也想用正则,不过不行,每次抓到的包Host后面不一定是Connection
 
{ THttp }

Type

THttp = class(TObject)
private
FHttpStr:TStrings;
FKeys:TStrings;
FValues:TStrings;
function GetItems(Key: String): String;
public
constructor Create();
destructor Destroy;

procedure SetHttp(AHttp:String);

property Values[Key:String]:String read GetItems; default;
end;

constructor THttp.Create;
begin
FKeys := TStringList.Create;
FValues := TStringList.Create;
FHttpStr := TStringList.Create;
end;

destructor THttp.Destroy;
begin
FHttpStr.Free;
FKeys.Free;
FValues.Free;
inherited Destroy;
end;

function THttp.GetItems(Key: String): String;
var
Index : Integer;
begin
Index := FKeys.IndexOf(Key);
if Index = -1 then
Result := ''
else
Result := FValues[Index];
end;


procedure THttp.SetHttp(AHttp: String);
procedure Parser(AStr:String);
begin
FKeys.Add(Copy(AStr,1, Pos(':',AStr) - 1));
FValues.Add( Copy(AStr, Pos(':',AStr) + 1, Length(AStr)));
end;
var
I:Integer;
begin
FHttpStr.Text := AHttp;
FValues.Clear;
FKeys.Clear;
for I := 1 to FHttpStr.Count - 1 do
begin
Parser(FHttpStr);
end;
end;

用法:
var
h : THttp;
begin
h := THttp.Create;
h.SetHttp('GET / HTTP/1.1'
+#13'Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/msword, application/vnd.ms-powerpoint, */*'
+#13'Accept-Language: zh-cn'
+#13'Accept-Encoding: gzip, deflate'
+#13'User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)'
+#13'Host: www.baidu.com'
+#13'Connection: Keep-Alive'
+#13'Cookie: BAIDUID=B6BA1FA1F179216F9F9B108E765DE0BD; PASSPORTRETRYSTRING=1182962306');
ShowMessage('Accept:'+h['Accept']);
ShowMessage('ccept-Language:'+h['Accept-Language']);
ShowMessage('Accept-Encoding:'+h['Accept-Encoding']);
ShowMessage('Host:'+h['Host']);
ShowMessage('Connection:'+h['Connection']);
ShowMessage('Cookie:'+h['Cookie']);
h.Free;
end;
 
后退
顶部