Mega Code Archive

 
Categories / Delphi / Examples
 

Using Anonymous Proxy Servers

Title: Using Anonymous Proxy Servers Question: If I am blocked from accessing a website because my ip address is banned, how do I bypass this? Answer: Using Anonymous Proxy Servers. If you are writing Internet applications, there may come across a time when your application is blocked from accessing a website. You will get error 403 your IP address is on a blocked list. In my case it happened that we had been given permission to use the data (owned by D) except it was in a website (owned by W). W didnt like us pulling Ds data even though D had given us permission. The data was extracted every night by a Delphi web application. For many people this will rarely be a problem because their IP address is allocated dynamically by their ISP. But if yours is static, you need to use an Anonymous Proxy Server. These are ip addresses which you plug into Internet Explorer or HTTP components (such as the ones provided by Winshoes). Anonymous Proxy Servers can be simple Perl scripts that people setup. They can last hours, days or months but do not rely on them. One day they are there- next day- gone. What is important is that the ip address that is logged by the server is the ip of the anonymous proxy, not yours. You can set the proxy server manually. The code below lets you get the Proxy Server in Ie under Windows Nt 4.0 so that it can be plugged into the HTTPGET component. It has not been tested under Windows 95, 98 or 2000. ieproxyip is the dotted quad part of the ip address and ieproxyport is the port (usually but not always 80). References to 10.0.0.2 are the local proxy server. Change these to your own. procedure GetIEProxy(var ieproxyip: string; var ieproxyport: Integer); var Registry: TRegistry; S: string; Index: Integer; keylist: TStringList; KeyName: string; procedure GetProxyDetails; var S, AproxyStr: string; Lastfound: Boolean; function SkipTo( Marker: string;var Text: string): string; var P: Integer; begin Marker := UpperCase(Marker); Lastfound := False; P := Pos(Marker, UpperCase(Text)); if P 0 then begin result := Copy(Text, P, Length(Text)); Lastfound := True; end else result:=''; end; function skipforward(N: Integer; ftext: string): string; begin Result := Copy(ftext, N + 1, 1000); end; function Skippast(const Marker: string;var Text: string): string; var tlf: Boolean; begin Result := SkipTo(Marker, Text); tlf := Lastfound; if Lastfound then Result := skipforward(Length(Marker), Result); Lastfound := tlf; end; function Textupto(const Marker: string;var Text: string): string; var P: Integer; begin Result := ''; Lastfound := False; P := Pos(UpperCase(Marker), UpperCase(Text)); if P 0 then begin Result := Copy(Text, 1, P - 1); Text := Copy(Text, P, Length(Text)); Lastfound := True; end; end; begin S := Registry.ReadString('ProxyServer'); if Pos('://', S) 0 then begin repeat S := Skippast('://', S); if Pos(';', S) 0 then AproxyStr := Textupto(';', S) else AproxyStr := S; until not Lastfound or (Pos('10.0.0.2', AproxyStr) = 0); end else AproxyStr := S; ieproxyip := ''; ieproxyport := 80; // Default if Index 0 then begin Index := Pos(':', AproxyStr); // find port if Index = 0 then ieproxyip := AproxyStr else begin ieproxyip := trim(Copy(AproxyStr, 1, Index - 1)); try ieproxyport := StrToInt(trim(Copy(AproxyStr, Index + 1, 10))); except end; end; end; end; begin Registry := TRegistry.Create; Registry.Access := Key_read; keylist := TStringList.Create; Registry.RootKey := HKEY_CURRENT_USER; if Registry.OpenKeyReadOnly('Software\Microsoft\Protected Storage System Provider') then begin Registry.GetKeyNames(keylist); S := keylist[0]; end else Exit; KeyName := S; Registry.RootKey := HKEY_USERS; if Registry.OpenKey(KeyName, False) then if Registry.HasSubkeys then begin KeyName := 'Software\Microsoft\Windows\CurrentVersion\Internet Settings'; if Registry.OpenKey(KeyName, False) then begin GetProxyDetails; end; end; Registry.Free; end; A good source of proxy server addresses is www.deny.de