?Ping App help - Delphi

Hi,
I am not so clued-up with developing network apps. I Wish to write a basic network ping appl, i believe using the ICMProtocol. I have noticed in the system32 dir is a ICMP.DLL module. Don't know how to use it.

Dev s/w : Delphi v5.0 Pro OS ms Win XP

Appl requirements -
I wish to send a ping to a specified ip adr on a regular basis,
eg every minute or such,
get result back : test ok/fail / data/time stamped etc.
This to test network equipment availability.

Else, if someone know of working commercial freeware utility that
can do such, plse advise? I do prefer to develope my own, however, for fun
and try-out.

Specs -
Input - IP address to send ping to
- Time period secs - minutes
- Type of test ? packets etc?
- File to capture to ?
- fucntion ==> Export to excel

Output - File info eg date : time : test result
- Screen : scroll back buffer or such
: Graph ?

If someone have a library comp/obj (even run appl for evaluation) for the ping send and result function as described or similar
With the ping-comp, I can probably develope my own appl with the input/output as above. However, if sample or working code is available for all, please let me know. I appreciate any pointers and help on this matter.

Comments

  • : Hi,
    : I am not so clued-up with developing network apps. I Wish to write a
    : basic network ping appl, i believe using the ICMProtocol. I have
    : noticed in the system32 dir is a ICMP.DLL module. Don't know how to
    : use it.
    :
    : Dev s/w : Delphi v5.0 Pro OS ms Win XP
    :
    : Appl requirements -
    : I wish to send a ping to a specified ip adr on a regular basis,
    : eg every minute or such,
    : get result back : test ok/fail / data/time stamped etc.
    : This to test network equipment availability.
    :
    : Else, if someone know of working commercial freeware utility that
    : can do such, plse advise? I do prefer to develope my own, however,
    : for fun
    : and try-out.
    :
    : Specs -
    : Input - IP address to send ping to
    : - Time period secs - minutes
    : - Type of test ? packets etc?
    : - File to capture to ?
    : - fucntion ==> Export to excel
    :
    : Output - File info eg date : time : test result
    : - Screen : scroll back buffer or such
    : : Graph ?
    :
    : If someone have a library comp/obj (even run appl for evaluation)
    : for the ping send and result function as described or similar
    : With the ping-comp, I can probably develope my own appl with the
    : input/output as above. However, if sample or working code is
    : available for all, please let me know. I appreciate any pointers
    : and help on this matter.
    :

    Use the TNMEcho component. The TTimer component can be used to provide the trigger for the ping.
  • Yes you can use icmp.dll for ping if you don't want to use socket component.

    Here's an example:

    [code]
    unit Ping;

    interface
    uses
    Windows, SysUtils, Classes;

    type
    TSunB = packed record
    s_b1, s_b2, s_b3, s_b4: byte;
    end;

    TSunW = packed record
    s_w1, s_w2: word;
    end;

    PIPAddr = ^TIPAddr;
    TIPAddr = record
    case integer of
    0: (S_un_b: TSunB);
    1: (S_un_w: TSunW);
    2: (S_addr: longword);
    end;

    IPAddr = TIPAddr;

    function IcmpCreateFile : THandle; stdcall; external 'icmp.dll';
    function IcmpCloseHandle (icmpHandle : THandle) : boolean; stdcall; external 'icmp.dll'
    function IcmpSendEcho (IcmpHandle : THandle; DestinationAddress : IPAddr;
    RequestData : Pointer; RequestSize : Smallint;
    RequestOptions : pointer;
    ReplyBuffer : Pointer;
    ReplySize : DWORD;
    Timeout : DWORD) : DWORD; stdcall; external 'icmp.dll';


    function Ping(InetAddress : string) : boolean;

    implementation

    uses
    WinSock;

    procedure TranslateStringToTInAddr(AIP: string; var AInAddr);
    var
    phe: PHostEnt;
    pac: PChar;
    GInitData: TWSAData;
    begin
    WSAStartup($101, GInitData);
    try
    phe := GetHostByName(PChar(AIP));
    if Assigned(phe) then
    begin
    pac := phe^.h_addr_list^;
    if Assigned(pac) then
    begin
    with TIPAddr(AInAddr).S_un_b do begin
    s_b1 := Byte(pac[0]);
    s_b2 := Byte(pac[1]);
    s_b3 := Byte(pac[2]);
    s_b4 := Byte(pac[3]);
    end;
    end
    else
    begin
    raise Exception.Create('Error getting IP from HostName');
    end;
    end
    else
    begin
    raise Exception.Create('Error getting HostName');
    end;
    except
    FillChar(AInAddr, SizeOf(AInAddr), #0);
    end;
    WSACleanup;
    end;

    function Ping(InetAddress : string) : boolean;
    var
    Handle : THandle;
    InAddr : IPAddr;
    DW : DWORD;
    rep : array[1..128] of byte;
    begin
    result := false;
    Handle := IcmpCreateFile;
    if Handle = INVALID_HANDLE_VALUE then
    Exit;
    TranslateStringToTInAddr(InetAddress, InAddr);
    DW := IcmpSendEcho(Handle, InAddr, nil, 0, nil, @rep, 128, 0);
    Result := (DW <> 0);
    IcmpCloseHandle(Handle);
    end;

    end.
    [/code]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories