程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> Delphi實現圖形化批量IP Ping

Delphi實現圖形化批量IP Ping

編輯:Delphi

/*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;

interface

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.

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved