当前位置:编程学习 > Delphi >>

Delphi实现图形化批量IP Ping

/*Title:Insun的故事

*Author:Insun

*Blog:http://yxmhero1989.blog.163.com

*From:www.4safer.com

*Reference:http://hi.baidu.com/ydbesl/blog/item/a16afa2ad14d8698033bf6a1.html

*/

ics控件下载地址http://www.huasoft.net/download/files/ics_d7.zip

当要检测的IP比较少时,我们一般直接使用DOS命令Ping来实现。但是,如果我们要检测的IP比较多时(比如一个网段),再用Ping命令就比较繁琐了,即使写一个批处理来实现,大把数据看起来也让人恼火。这里,我们用Delphi实现对批量IP的检测,检测结果用明了的图形显示,效果如下:

Delphi实现图形化批量IP Ping - InSun - Minghacker is Insun

  Delphi treeview添加背景图片

procedure TForm1.FormCreate(Sender: TObject);
begin
form1.TreeView1 .Brush.Bitmap:=image1.Picture.Bitmap;
end;

DELPHI自带的DEMO    ..demoscustomdraw   不错。

不知bkMode怎么设为transparent,求指导。

//setBkmode(Canvas.Handle,transparent);

      unit Unit1;

inte易做图ce

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ImgList, Ping, ComCtrls, jpeg, ExtCtrls, WinSkinData;

type
  TForm1 = class(TForm)
    TreeView1: TTreeView;
    Ping1: TPing;
    ImageList1: TImageList;
    GroupBox1: TGroupBox;
    Label1: TLabel;
    Edit1: TEdit;
    Label2: TLabel;
    Edit2: TEdit;
    Edit3: TEdit;
    Label3: TLabel;
    Button1: TButton;
    Label4: TLabel;
    SkinData1: TSkinData;
    Image1: TImage;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
   private
  Function Ping(strip:string):Boolean;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
   i:Integer;

implementation

{$R *.dfm}
Function TForm1.Ping(strip:string):Boolean;
Begin
ping1.address:=Trim(strip);
Ping1.ping;
if ping1.ErrorCode=0 then
begin
ping:=True;
end
Else
Begin
ping:=False;
i:=i+1;
End;
End;


procedure TForm1.Button1Click(Sender: TObject);
Var
h:Integer;
treenode1,treenode2:TTreeNode;
begin
//清空所有Item;
TreeView1.Items.Clear;
 
With TreeView1.Items Do
Begin
//增加根接点;
TreeNode1:=Add(nil, 批量IP检测);
//全部展开所有结点
TreeView1.FullExpand;
//刷新TreeView
TreeView1.Refresh;
//根结点图标
TreeNode1.ImageIndex:=0;
TreeNode1.SelectedIndex:=0;
//二级接点
For h:=StrToInt(Trim(Edit2.Text)) To StrToInt(Trim(Edit3.Text)) Do
Begin
if ping(Trim(Edit1.Text)+.+Trim(IntToStr(h)))=True Then
Begin
//如果可以Ping通,图标为0;
TreeNode2:=AddChild(TreeNode1,Trim(Edit1.Text)+.+IntToStr(h));
TreeNode2.ImageIndex:=0;
TreeNode2.SelectedIndex:=0;
//全部展开所有结点
TreeView1.FullExpand;
//刷新TreeView
TreeView1.Refresh;
End
Else
Begin
//如果不能Ping通,图标为1
TreeNode2:=AddChild(TreeNode1,Trim(Edit1.Text)+.+IntToStr(h));
TreeNode2.ImageIndex:=1;
TreeNode2.SelectedIndex:=1;
//全部展开所有结点
TreeView1.FullExpand;
//刷新TreeView
TreeView1.Refresh;
End;
End;
h:=h+1;
End;
Label4.Caption:=检测结果:+IntToStr(i)+ 个IP不能Ping通;
Application.MessageBox(检测结束,提示,0);
End;

procedure TForm1.FormCreate(Sender: TObject);
begin
form1.TreeView1 .Brush.Bitmap:=image1.Picture.Bitmap;
end;

end.

补充:软件开发 , Delphi ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,