全部家当!求Wininet中的InternetQueryOption的用法!(100分)

  • 主题发起人 主题发起人 fbc-gc
  • 开始时间 开始时间
F

fbc-gc

Unregistered / Unconfirmed
GUEST, unregistred user!
var
info: TInternetProxyInfo;
i: cardinal;
begin
{ TODO -oUser -cConsole Main : Insert code here }
while (true) do
begin
try
InternetQueryOption(nil, INTERNET_OPTION_PROXY, @info, i);
except
begin
raise Exception.Create('Error in query ProxyEnabled');
exit;
end;
end;
write(inttostr(i)+' : ');
writeln(inttobin(i));
end;
请高手讲讲返回值i和当前代理设置的关系.
我现在只知道i=12时IE不使用代理!
 
INTERNET_STATE_CONNECTED :$00000001 连接状态;
INTERNET_STATE_DISCONNECTED :$00000002 非连接状态(和 INTERNET_STATE_CONNECTED 对应);
INTERNET_STATE_DISCONNECTED_BY_USER :$00000010 用户请求的非连接状态
INTERNET_STATE_IDLE :$00000100 连接状态,并且空闲
INTERNET_STATE_BUSY :$00000200 连接状态,正在响应连接请求
如:InternetQueryOption(nil, INTERNET_OPTION_CONNECTED_STATE, @ConnectState, StateSize)
InternetQueryOption 函数的检测结果只能表明当前的Internet设置是可用的,并不能表示计算机一定能访问Internet。
其INTERNET_OPTION_PROXY参数对应的具体值不同!
其实你可以使用InternetGetConnectedState,包含参数如下:
INTERNET_CONNECTION_MODEM 本地机器通过MODEM连接Internet
INTERNET_CONNECTION_LAN 本地机器通过局域网连接Internet
INTERNET_CONNECTION_PROXY 本地机器通过代理连接Internet
INTERNET_CONNECTION_MODEM_BUSY 本地机器的MODEM BUSY无法连接Internet
如:
var Flags, Reserved : DWORD
begin . . . .
Reserved := 0;
if InternetGetConnectedState( Flags, Reserved ) then
begin
if (Flags or INTERNET_CONNECTION_MODEM) <> 0 then
writeln( 'Connected by modem' ) else if (Flags or INTERNET_CONNECTION_LAN ) <> 0 then
writeln( 'Connected by LAN' );
end else writeln( 'There is no active Internet connection' );
比InternetQueryOption更通用有效,你可以不管是什么浏览器的区别了!
 
谢谢YB_unique!
可我是想通过InternetQueryOption(nil, INTERNET_OPTION_PROXY, @info, i)来判断
当前代理服务器的设置情况,包括:使用那几种类型的代理(http,socks..),是否跳过本地ip,
是否使用同一代理.其实这些就是IE的internet 设置中的连接设置.
 
你最好先到[HKEY_CURRENT_USER/Software/Microsoft/Windows/CurrentVersion/Internet Settings]仔细看看!
不同的代理方式值应该不同,你可以自己改变试试!
具体的我也不大清楚!
下面这段程序可以让你获得代理的相关信息!
uses WinInet UrlMon
procedure TForm1.Button1Click(Sender: TObject);
var info:TInternetProxyInfo;
lngth:integer;
o,i:integer;
h:integer;
proxy :pChar;
bypass :PChar;
begin
proxy:=pchar('127.0.0.1:8080'); // 代理地址及端口
bypass:=pChar('');
info.dwAccessType := INTERNET_OPEN_TYPE_PROXY ;
//INTERNET_OPEN_TYPE_DIRECT 直接连接Internet 无代理
//INTERNET_OPEN_TYPE_PRECONFIG 设置
//INTERNET_OPEN_TYPE_PROXY 代理服务
info.lpszProxy :=proxy;
info.lpszProxyBypass:=bypass;
lngth:=sizeof(info);
h:=UrlMkSetSessionOption(INTERNET_OPTION_PROXY ,@info,lngth,0);
end;


 
MSDN中的详细说明!
http://msdn.microsoft.com/library/default.asp?url=/workshop/networking/wininet/reference/constants/flags.asp
 
InternetQueryOption
BOOL InternetQueryOption(
IN HINTERNET hInternet,
IN DWORD dwOption,
OUT LPVOID lpBuffer,
IN OUT LPDWORD lpdwBufferLength );

Queries an Internet option on the specified handle. Returns TRUE if successful, or FALSE otherwise.
To get a specific error message, call GetLastError.

hInternet
Internet handle on which to query information.
dwOption
Internet option to query. Can be one of the Option Flags values.
lpBuffer
Address of a buffer that receives the option setting.
lpdwBufferLength
Address of a variable that contains the length of lpBuffer. When the function returns, the variable
receives the length of the data placed into lpBuffer. If GetLastError returns ERROR_INSUFFICIENT_BUFFER,
this parameter receives the number of bytes required to hold the created URL.
 
Internet option to query. Can be one of these values:
INTERNET_OPTION_CALLBACK
Returns the address of the callback function defined for this handle.
INTERNET_OPTION_CONNECT_TIMEOUT
Returns the time-out value in milliseconds to use for Internet connection requests.
If a connection request takes longer than this time-out value, the request is canceled.
The default time-out value is infinite.
INTERNET_OPTION_CONNECT_RETRIES
Returns the retry count to use for Internet connection requests. If a connection attempt
still fails after the specified number of tries, the request is canceled. The default is
five retries.
INTERNET_OPTION_CONNECT_BACKOFF
Returns the delay value, in milliseconds, to wait between connection retries. (This flag
is currently not implemented.)
INTERNET_OPTION_CONTROL_SEND_TIMEOUT
Returns the time-out value, in milliseconds, to use for non-data (control) Internet send
requests. If a non-data send request takes longer than this time-out, the request is canceled.
The default time-out is infinite. Currently, this value has meaning only for FTP sessions.
INTERNET_OPTION_CONTROL_RECEIVE_TIMEOUT
Returns the time-out value, in milliseconds, to use for non-data (control) Internet receive
requests. If a non-data receive request takes longer than this time-out value, the request
is canceled. The default time-out is infinite. Currently, this value has meaning only for
FTP sessions.
INTERNET_OPTION_DATA_SEND_TIMEOUT
Returns the time-out value, in milliseconds, to use for Internet data send requests. If a
data send request takes longer than this time-out value, the request is canceled. The default
time-out value is infinite.
INTERNET_OPTION_DATA_RECEIVE_TIMEOUT
Returns the time-out value, in milliseconds, to use for Internet data receive requests. If a
data receive request takes longer than this time-out value, the request is canceled. The
default time-out value is infinite.
INTERNET_OPTION_HANDLE_TYPE
Returns the type of the Internet handle passed in.
INTERNET_HANDLE_TYPE_CONNECT_HTTP
INTERNET_HANDLE_TYPE_FTP_FIND
INTERNET_HANDLE_TYPE_FTP_FIND_HTML
INTERNET_HANDLE_TYPE_FTP_FILE
INTERNET_HANDLE_TYPE_FTP_FILE_HTML
INTERNET_HANDLE_TYPE_GOPHER_FIND
INTERNET_HANDLE_TYPE_GOPHER_FIND_HTML
INTERNET_HANDLE_TYPE_GOPHER_FILE
INTERNET_HANDLE_TYPE_GOPHER_FILE_HTML
INTERNET_HANDLE_TYPE_HTTP_REQUEST

INTERNET_OPTION_CONTEXT_VALUE
Returns the context value associated with this Internet handle.
INTERNET_OPTION_READ_BUFFER_SIZE
Returns the size of the read buffer (for example, the buffer used by FtpGetFile).
INTERNET_OPTION_WRITE_BUFFER_SIZE
Returns the size of the write buffer (for example, the buffer used by FtpPutFile).
INTERNET_OPTION_ASYNC_PRIORITY
Returns the priority of this download if it is an asynchronous download.
INTERNET_OPTION_PARENT_HANDLE
Returns the parent handle of this handle.
INTERNET_OPTION_KEEP_CONNECTION
Returns an indication whether this handle uses persistent connections. Can be one of these
values: INTERNET_KEEP_ALIVE_UNKNOWN INTERNET_KEEP_ALIVE_ENABLED INTERNET_KEEP_ALIVE_DISABLED
INTERNET_OPTION_USERNAME
Returns the user name associated with a handle returned by InternetConnect.
INTERNET_OPTION_PASSWORD
Returns the password associated with the handle returned by InternetConnect.
INTERNET_OPTION_REQUEST_FLAGS
Returns special status flags about the current download in progress. The only flag that is returned
at this time is INTERNET_REQFLAG_FROM_CACHE. This is the way for the caller to find out whether a
request is being satisfied from the cache.
INTERNET_OPTION_EXTENDED_ERROR
Returns the Windows Sockets error code that was mapped to the ERROR_INTERNET_ error codes last returned
in this thread context.
INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
Returns the certificate for an SSL/PCT server into the INTERNET_CERTIFICATE_INFO structure.
INTERNET_OPTION_SECURITY_CERTIFICATE
Returns the certificate for an SSL/PCT server into a formatted string.
INTERNET_OPTION_SECURITY_KEY_BITNESS
Returns the bit size of the encryption key. The larger the number, the greater the encryption strength
being used.
INTERNET_OPTION_OFFLINE_MODE
Not currently implemented.
INTERNET_OPTION_CACHE_STREAM_HANDLE
Returns the file handle being used to write the cached data.
INTERNET_OPTION_ASYNC
Not currently implemented.
INTERNET_OPTION_SECURITY_FLAGS
Returns the security flags for a handle. Can be a combination of these values: SECURITY_FLAG_128BIT
SECURITY_FLAG_40BIT
SECURITY_FLAG_56BIT
SECURITY_FLAG_IETFSSL4
SECURITY_FLAG_IGNORE_CERT_CN_INVALID
SECURITY_FLAG_IGNORE_CERT_DATE_INVALID
SECURITY_FLAG_IGNORE_REDIRECT_TO_HTTP
SECURITY_FLAG_IGNORE_REDIRECT_TO_HTTPS
SECURITY_FLAG_NORMALBITNESS
SECURITY_FLAG_PCT
SECURITY_FLAG_PCT4
SECURITY_FLAG_SECURE
SECURITY_FLAG_SSL
SECURITY_FLAG_SSL3
SECURITY_FLAG_UNKNOWNBIT

INTERNET_OPTION_DATAFILE_NAME
Returns the name of the file backing a downloaded entity.
INTERNET_OPTION_URL
Returns the full URL of a downloaded entity.
INTERNET_OPTION_REFRESH
Returns TRUE if variables are allowed to be re-read from the registry for a handle.
INTERNET_OPTION_PROXY
Returns the proxy information on an existing InternetOpen handle when the process handle is not NULL.
If the process handle is NULL, the API sets or queries the global proxy information. The lpBuffer
parameter is an INTERNET_PROXY_INFO structure that contains the proxy information.
INTERNET_OPTION_VERSION
Returns the version number of Wininet.dll. The lpBuffer parameter is the address of an INTERNET_
VERSION_INFO structure.
INTERNET_OPTION_USER_AGENT
Returns the user agent string on handles supplied by InternetOpen and used in subsequent HttpSendRequest,
so long as it is not overridden by a header added by HttpAddRequestHeaders or HttpSendRequest.
 
wininet单元的详细定义!
http://doc.ddart.net/msdn/header/include/wininet.h.html
 
谢谢YB_unique
看来我只所以用InternetQueryOption(nil, INTERNET_OPTION_PROXY, @info, i)
就是不想能读注册表,因为我如果监视频率很大的话那用户的硬盘灯就闪个不停了,谁还敢用我
的程序?
 
想完全正确识别判断代理类型很难!如WinGate和socks代理就是不同的概念,而且很多代理很难区分!
如Telnet代理。其实关键是判断代理与否,如果想要正确判断,肯怕还要监视端口!
 
麻烦你啦,谢谢!
 
后退
顶部