Delphi detects whether the remote host is survived in Delphi

xiaoxiao2021-03-06  14

Delphi detects whether the remote host is survived in Delphi

2005-03-10 JLBNET

Network communication often requires determining whether the remote host survives to determine the next operation. You can use the ICMP protocol directly, but you should consider that many protocol details are taken, it is more troublesome. Windows comes with an outgoing ICMP library that can be used, as long as the corresponding data structure is filled before use.

The following is the data structure to use. These structures have a C-form declaration in MSDN, which is given herein in the form of Delphi.

// The protocol data structure for use pipoptioninfo = ^ Tipoptioninfo; // ip header option Tipoptioninfo = Packed Record Ttl: Byte; // Survival time TOS: BYTE; // Type of Service, request type Flags: Byte; // Sign OptionsSize : Byte; // Option length OptionsData: Pchar; // Option data end; picmpechoreply = ^ TicmpechorePly; ticmpechoreply = PACKED RECORD // ICMP Return Information Address: DWORD; // IP address status: dword; // State RTT: DWORD; DataSize: Word; // Data Length Reserved: Word; // Reserved Data: Pointer; // Data Options: TipoptionInfo; // Options Area end;

// function declaration in a dynamic library TIcmpCreateFile = function: THandle; stdcall; // Create an ICMP handle TIcmpCloseHandle = function (IcmpHandle: THandle): Boolean; stdcall; // close handle ICMP TIcmpSendEcho = function (IcmpHandle: THandle; DestinationAddress: DWORD RequestData: Pointer; RequestSize: Word; RequestOptions: Pipoptioninfo; ReplyBuffer: Pointer; ReplySize: DWORD; TIMEOUT: DWORD: DWORD; stdcall; // Send ICMP probe

// The variables to be used in the Variables, HiCMPDLL, HICMP: Thandle; Wsadata: TWSADATA; ICMPCREATEFILE: TiCMpCreateFile; ICMPCloseHandle: TicmpCloseHandle; ICMPSendecho: TiCmpsenDecho

转载请注明原文地址:https://www.9cbs.com/read-48484.html

New Post(0)