function rtnCHeckProxy(ptype:integer;Host:string;Port:i nteger;user,pass:string;var ip,country:string):boolean;
var
Fhttp: TIdHTTP;
FMultiStream: TIdMultiPartFormDataStream;
IdSocksInfo : TIdSocksInfo;
Fhandler : TIdIOHandlerStack;
html :string;
d : integer;
begin
result := false;
application.ProcessMessages;
Fhttp := TIdHTTP.Create(nil);
Fhandler := TIdIOHandlerStack.Create(nil);
FMultiStream := TIdMultiPartFormDataStream.Create;
Fhttp.IOHandler := Fhandler;
IdSocksInfo := nil;
try
if (Host <> '') and (Port<>0) then
begin
if (ptype = 0) then
begin
Fhttp.ProxyParams.ProxyServer := Host;
Fhttp.ProxyParams.ProxyPort := Port;
if (user <> '') and (pass <> '') then
begin
Fhttp.ProxyParams.BasicAuthentication := true;
Fhttp.ProxyParams.ProxyUsername := user;
Fhttp.ProxyParams.ProxyPassword := pass;
end;
end else
begin
IdSocksInfo := TIdSocksInfo.Create(nil);
IdSocksInfo.Host := Host;
IdSocksInfo.Port := port;
if (user <> '') and (pass <> '') then
begin
IdSocksInfo.Authentication := saUsernamePassword;
IdSocksInfo.Username := user;
IdSocksInfo.Password := pass;
end else
begin
IdSocksInfo.Authentication := saNoAuthentication;
end;
case ptype of
1 : IdSocksInfo.Version := svSocks4;
2 : IdSocksInfo.Version := svSocks4A;
3 : IdSocksInfo.Version := svSocks5;
end;
Fhandler.TransparentProxy := IdSocksInfo;
end;
Fhttp.HandleRedirects := true;
Fhttp.Request.Connection := 'close';
Fhttp.ReadTimeout := 50000;
try
html := Fhttp.get('http://get-myip.com/');
d := pos(pattern1,html);
if (d<>0) then
begin
delete(html,1,d+length(pattern1));
ip := copy(html,1,pos('</b></div>',html)-1);
end;
d := pos(pattern2,html);
if (d<>0) then
begin
delete(html,1,d+length(pattern2));
country := copy(html,1,pos('<br>',html)-1);
end;
result := (ip<>'') and (country <> '');
Except
on e:exception do
memo2.Lines.Add(host+'failed'+E.Message);
end;
end;
finally
if assigned(IdSocksInfo) then IdSocksInfo.Free;
if assigned(Fhandler) then Fhandler.Free;
if assigned(Fhttp) then Fhttp.Free;
if assigned(FMultiStream) then FMultiStream.Free;
end;
end;
var
Fhttp: TIdHTTP;
FMultiStream: TIdMultiPartFormDataStream;
IdSocksInfo : TIdSocksInfo;
Fhandler : TIdIOHandlerStack;
html :string;
d : integer;
begin
result := false;
application.ProcessMessages;
Fhttp := TIdHTTP.Create(nil);
Fhandler := TIdIOHandlerStack.Create(nil);
FMultiStream := TIdMultiPartFormDataStream.Create;
Fhttp.IOHandler := Fhandler;
IdSocksInfo := nil;
try
if (Host <> '') and (Port<>0) then
begin
if (ptype = 0) then
begin
Fhttp.ProxyParams.ProxyServer := Host;
Fhttp.ProxyParams.ProxyPort := Port;
if (user <> '') and (pass <> '') then
begin
Fhttp.ProxyParams.BasicAuthentication := true;
Fhttp.ProxyParams.ProxyUsername := user;
Fhttp.ProxyParams.ProxyPassword := pass;
end;
end else
begin
IdSocksInfo := TIdSocksInfo.Create(nil);
IdSocksInfo.Host := Host;
IdSocksInfo.Port := port;
if (user <> '') and (pass <> '') then
begin
IdSocksInfo.Authentication := saUsernamePassword;
IdSocksInfo.Username := user;
IdSocksInfo.Password := pass;
end else
begin
IdSocksInfo.Authentication := saNoAuthentication;
end;
case ptype of
1 : IdSocksInfo.Version := svSocks4;
2 : IdSocksInfo.Version := svSocks4A;
3 : IdSocksInfo.Version := svSocks5;
end;
Fhandler.TransparentProxy := IdSocksInfo;
end;
Fhttp.HandleRedirects := true;
Fhttp.Request.Connection := 'close';
Fhttp.ReadTimeout := 50000;
try
html := Fhttp.get('http://get-myip.com/');
d := pos(pattern1,html);
if (d<>0) then
begin
delete(html,1,d+length(pattern1));
ip := copy(html,1,pos('</b></div>',html)-1);
end;
d := pos(pattern2,html);
if (d<>0) then
begin
delete(html,1,d+length(pattern2));
country := copy(html,1,pos('<br>',html)-1);
end;
result := (ip<>'') and (country <> '');
Except
on e:exception do
memo2.Lines.Add(host+'failed'+E.Message);
end;
end;
finally
if assigned(IdSocksInfo) then IdSocksInfo.Free;
if assigned(Fhandler) then Fhandler.Free;
if assigned(Fhttp) then Fhttp.Free;
if assigned(FMultiStream) then FMultiStream.Free;
end;
end;
Nenhum comentário:
Postar um comentário