unit IEProxy;
interface
uses WinInet, SysUtils, Windows;
type
TProtocol = (http,
https,
ftp,
gopher,
socks);
TProxyInfo =
record
Servername: ShortString;
Port : word;
end;
function GetProxyServer(protocol: TProtocol;
var ProxyServer:
string;
var ProxyPort: word): Boolean;
overload;
function GetProxyServer(protocol: TProtocol;
var ServerInfo: TProxyInfo): Boolean;
overload;
implementation
function ProtocolToString(Protocol: TProtocol):
string;
begin
case Protocol
of
http : Result := '
http';
https : Result := '
https';
ftp : Result := '
ftp';
gopher: Result := '
gopher';
socks : Result := '
socks';
else Result := '
';
end;
end;
function GetProxyInformation:
string;
var
ProxyInfo: PInternetProxyInfo;
Len: LongWord;
begin
Result := '
';
Len := 4096;
GetMem(ProxyInfo, Len);
try
if InternetQueryOption(
nil, INTERNET_OPTION_PROXY, ProxyInfo, Len)
then
if ProxyInfo^.dwAccessType = INTERNET_OPEN_TYPE_PROXY
then
begin
Result := ProxyInfo^.lpszProxy
end;
finally
FreeMem(ProxyInfo);
end;
end;
{**************************************************************************
* NAME: GetProxyServer
* DESC: Proxy-Server Einstellungen abfragen
* PARAMS: protocol => z.B. 'http' oder 'ftp'
* RESULT: Boolean (Proxy für Protokoll eingetragen)
* CREATED: 08-04-2004/shmia
* MODIFIED: 11-01-2008/DeddyH
*************************************************************************}
function GetProxyServer(protocol: TProtocol;
var ProxyServer:
string;
var ProxyPort: word): Boolean;
var
i : Integer;
proxyinfo, prot :
string;
begin
Result := false;
ProxyServer := '
';
ProxyPort := 0;
proxyinfo := AnsiLowerCase(GetProxyInformation);
if proxyinfo = '
'
then
Exit;
prot := ProtocolToString(protocol) + '
=';
i := Pos(prot, proxyinfo);
if i > 0
then
begin
Delete(proxyinfo, 1, i + Pred(Length(prot)));
i := Pos('
;', proxyinfo);
if i > 0
then
proxyinfo := Copy(proxyinfo, 1, i-1)
else
begin
i := Pos(#32,proxyinfo);
if i > 0
then
proxyinfo := Copy(proxyinfo, 1, i-1);
end;
Result := true;
end;
i := Pos('
:', proxyinfo);
if i > 0
then
begin
ProxyPort := StrToIntDef(Copy(proxyinfo, i+1, Length(proxyinfo)-i), 0);
ProxyServer := Copy(proxyinfo, 1, i-1);
Result := true;
end;
end;
function GetProxyServer(protocol: TProtocol;
var ServerInfo: TProxyInfo): Boolean;
var s:
string;
i: word;
begin
Result := GetProxyServer(protocol,s,i);
ServerInfo.Servername := s;
ServerInfo.Port := i;
end;
end.