cmpclosehandle = nil) or (@icmpsendecho = nil) then begin result:=false; halt; end; hicmp := icmpcreatefile; if hicmp = invalid_handle_value then begin result:=false; halt; end; end else begin result:=false; halt; end; // ------------------------------------------------------------ address := inet_addr(pchar(ipaddr)); if (address = inaddr_none) then begin phe := gethostbyname(pchar(ipaddr)); if phe = nil then result:=false else begin address := longint(plongint(phe^.h_addr_list^)^); hostname := phe^.h_name; hostip := strpas(inet_ntoa(tinaddr(address))); end; end else begin phe := gethostbyaddr(@address, 4, pf_inet); if phe = nil then result:=false; end;
if address = inaddr_none then begin result:=false; end; // get some data buffer space and put something in the packet to send buffersize := sizeof(ticmpechoreply) + size; getmem(preqdata, size); getmem(pdata, size); getmem(pipe, buffersize); fillchar(preqdata^, size, $aa); pipe^.data := pdata;
// finally send the packet fillchar(ipopt, sizeof(ipopt), 0); ipopt.ttl := 64; npkts := icmpsendecho(hicmp, address, preqdata, size, @ipopt, pipe, buffersize, timeout); if npkts = 0 then result:=false;
// free those buffers freemem(pipe); freemem(pdata); freemem(preqdata);
// -------------------------------------------------------------- icmpclosehandle(hicmp); freelibrary(hicmplib); // free winsock if wsacleanup <> 0 then result:=false; end;
{================================================================= 功 能: 检测计算机是否上网 参 数: 无 返回值: 成功: true 失败: false; 备 注: uses wininet 版 本: 1.0 2002/10/07 13:33:00 =================================================================} function internetconnected: boolean; const // local system uses a modem to connect to the internet. internet_connection_modem = 1; // local system uses a local area network to connect to the internet. internet_connection_lan = 2; // local system uses a proxy server to connect to the internet. internet_connection_proxy = 4; // local system's modem is busy with a non-internet connection. internet_connection_modem_busy = 8; var dwconnectiontypes : dword; begin dwconnectiontypes := internet_connection_modem+ internet_connection_lan + internet_c |