或者说如何检查收到的IP报文
看看是否是ping程序发来的ICMP报文
提取出其ip

解决方案 »

  1.   

    据说VC可以!DELPHI的不知道!学习
      

  2.   

    unit ping;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ExtCtrls, IdBaseComponent, IdComponent, IdRawBase,
      IdRawClient, IdIcmpClient;type
      TPingFrm = class(TForm)
        ICMP: TIdIcmpClient;
        Panel1: TPanel;
        Button1: TButton;
        Button2: TButton;
        Edit1: TEdit;
        Label1: TLabel;
        ListBox1: TListBox;    procedure Button2Click(Sender: TObject);
        procedure ICMPReply(ASender: TComponent;
          const AReplyStatus: TReplyStatus);
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      PingFrm: TPingFrm;implementation{$R *.dfm}
    procedure TPingFrm.Button2Click(Sender: TObject);
    begin
    ListBox1.Clear ;
    end;procedure TPingFrm.ICMPReply(ASender: TComponent;
      const AReplyStatus: TReplyStatus);
    var
    sTime: string;
    begin
    if AReplyStatus.ReplyStatusType=rsError  then showmessage('hello*');
    if (AReplyStatus.MsRoundTripTime = 0 ) then
    sTime := '<1'
    else
    sTime := '=';
    ListBox1.Items.Add(Format('ICMP_SEQ=%d Reply from %s [%s] : Bytes=%d time%s%d ms TTL=%d',
    [AReplyStatus.SequenceId,
    Edit1.Text,
    AReplyStatus.FromIpAddress,
    AReplyStatus.BytesReceived,
    sTime,
    AReplyStatus.MsRoundTripTime,
    AReplyStatus.TimeToLive]));
    end;procedure TPingFrm.Button1Click(Sender: TObject);
    var
    i : integer;
    begin
    ICMP.Host := Edit1.Text ;
    ICMP.ReceiveTimeout := 1000;
    Button1.Enabled := false;
    try
    for i:=0 to 3 do
    begin
    ICMP.Ping ;
    Application.ProcessMessages ;
    end;
    except
     on e:exception do  showmessage('hlo*')  ;
    end;
    finally
    Button1.Enabled := true;
    end;
    end;
    end.