http://www.csdn.net/expert/topic/169/169977.shtm
也许这个程序对你有用

解决方案 »

  1.   

    to: liuguantocsdn() 
    这样怎么能行?繁忙就是繁忙,空闲就是空闲,怎么可以粗略呢?
      

  2.   

    你要用ping,你是在2000,还是98下?
    若98下,我有代码,留个mail
      

  3.   

    98 下的代码发过来:[email protected] 谢谢
      

  4.   

    : chendaiyin(唉呀!) :
    源码发出了!
      

  5.   

    ch81(missile) :
    那东东有多大呀?怎么收了好久也没收下来?源码不可能有这么大?
      

  6.   

    里面多了我编译好的exe!那我重新发一个只有源码的!
      

  7.   

    参考InternetGetConnectedStateEx 函数!!!
      

  8.   

    To: ch81(missile)
        你发的那个程序已收到但我看不懂,我现在将近它贴出来,能不能帮忙解释一下?
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls,winsock;
    type
            PIPOptionInformation = ^TIPOptionInformation;
            TIPOptionInformation = packed record
                    TTL: Byte;
                    TOS: Byte;
                    Flags: Byte;
                    OptionsSize: Byte;
                    OptionsData: PChar;
            end;
            PIcmpEchoReply = ^TIcmpEchoReply;
            TIcmpEchoReply = packed record
                    Address: DWORD;
                    Status: DWORD;
                    RTT: DWORD;
                    DataSize: Word;
                    Reserved: Word;
                    Data: Pointer;
                    Options: TIPOptionInformation ;
            end;
    type
      TForm1 = class(TForm)
        Button1: TButton;
        Edit1: TEdit;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
            
        { Public declarations }
      end;
      function IcmpCreateFile:THandle;stdcall;
      function IcmpCloseHandle(IcmpHandle:THandle):Bool;stdcall;
      function IcmpSendEcho(IcmpHandle:THandle;DestinationAddress:DWORD;RequestData:Pointer;RequestSize:Word;RequestOptions:PIPOptionInformation;ReplyBuffer: Pointer;ReplySize: DWord;Timeout: DWord): DWord; stdcall;
    var
      Form1: TForm1;implementation{$R *.DFM}
    function IcmpCreateFile;external 'icmp.dll';
    function IcmpCloseHandle;external 'icmp.dll';
    function IcmpSendEcho;external 'icmp.dll';
    procedure TForm1.Button1Click(Sender: TObject);
    var Icmp:THandle;
    var IPAddress:Dword;
    var pReqData,pRevData:PChar;
    var pIPE:PIcmpEchoReply;// ICMP Echo reply buffer
    var IPOpt:TIPOptionInformation;// IP Options for packet to send
    var Size: DWORD;
    var MyString:string;
    var TimeOut:DWORD;
    var BufferSize:DWORD;
    begin
            Icmp:=IcmpCreateFile;
            IPAddress:=inet_addr(PChar(Edit1.Text));
            Size:=40;
            BufferSize:=SizeOf(TICMPEchoReply)+Size;
            GetMem(pRevData,Size);
            GetMem(pIPE,BufferSize);
            FillChar(pIPE^,SizeOf(pIPE^),0);
            pIPE^.Data := pRevData;
            MyString:='Hello,World';
            pReqData := PChar(MyString);
            FillChar(IPOpt,Sizeof(IPOpt),0);
            IPOpt.TTL:=64;
            TimeOut:=4000;
            IcmpSendEcho(Icmp,IPAddress,pReqData,Length(MyString),@IPOpt,pIPE,BufferSize,TimeOut);
            if pReqData^ = pIPE^.Options.OptionsData^ then
            begin
                    ShowMessage(Edit1.Text+' '+IntToStr(pIPE^.DataSize) +' '+IntToStr(pIPE^.RTT));
            end;
            FreeMem(pRevData);
            FreeMem(pIPE);end;end.
      

  9.   

    如果你要看懂这个程序,你得先看一下icmp协议,其中的一个回显命令(好像是)
    这个是98下的一个系统提供的icmp.dll,这个程序我也只能看懂各个赋值有什么用。
    icmpIcmpCreateFile这个应该还有很多用法,其他用法我不会!
    上面用法是,你的机器发出'Hello,World'到那边的机器,然后那边的机器收到后则立刻返回同个字串,所以通过来回时间。来判断连通的质量