Transfer from: http: //blog.9cbs.net/nanfansky/archive/2005/01/13/251162.aspx// LAN hosts // search Date: 2005.01.12 // Author: nanfansky // Reference: http: // Blog.aspcool.com/jiezhi
Using system.drawing; using system.collections; using system.bomponentmodel; using system.data; using system.net; using system.threading;
A summary description of Namespace Windowlansearch {///
Public Form1 () {// // Windows Form Designer Support for // InitializeComponent (); Initlanhost (); ProgressBarsearch.maximum = 255;
// // Todo: Add any constructor code after INITIALIZEComponent call //}
///
///
#REGION Windows Form Designer The code ///
/// summary> private void InitializeComponent () {this.textBox1 = new System.Windows.Forms.TextBox (); this.button1 = new System.Windows.Forms.Button (); this.progressBarSearch = new System. Windows.Forms.ProgressBar (); this.listView1 = new System.Windows.Forms.ListView (); this.columnHeader1 = new System.Windows.Forms.ColumnHeader (); this.columnHeader2 = new System.Windows.Forms.ColumnHeader (); This.suspendlayout (); /// textBox1 // this.textBox1.Location = new system.drawing.point (24, 40); this.textbox1.multiline = true; this.textbox1.name = "TextBox1 "; this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Both; this.textBox1.Size = new System.Drawing.Size (176, 296); this.textBox1.TabIndex = 0; this.textBox1.Text = ""; // // button1 // this.button1.location = new system.drawing.point (456, 40); this.button1.name = "button1"; this.button1.tabindex = 1; this.button1. Text = "Start Search"; this.button1.click = new system.eventhandler (t his.button1_Click); // // progressBarSearch // this.progressBarSearch.Location = new System.Drawing.Point (32, 360); this.progressBarSearch.Name = "progressBarSearch"; this.progressBarSearch.Size = new System.Drawing .Size (490, 24); this.progressBarSearch.TabIndex = 2; // // listView1 // this.listView1.Columns.AddRange (new System.Windows.Forms.ColumnHeader [] {this.columnHeader1, this.columnHeader2} This.listview1.location = new system.drawing.point (248, 40); this.listview1.name = "listview1";
This.listview1.size = new system.drawing.size (184, 288); this.listview1.tabindex = 5; /// ColumnHeader1 // this.columnheader1.text = "dddd"; // // ColumnHeader2 /// This.ColumnHeader2.text = "sssss"; // // Form1 // this.autoscalebasesize = new system.drawing.size (6, 14); this.clientsize = new system.drawing.size (544, 413); this .Controls.add (this.listview1); this.controls.add (this.progressbarsearch); this.controls.add (this.button1); this.controls.add (this.TextBox1); this.name = "form1" This.Text = "form1"; this.ResumeLayout (false);} #ENDREGION
///
Threadstart threadmeth;
Thread threadProgress = New Threadstart (New ThreadSTARCH); threadprogress.start ();
String localhost = (DNS.GethOstName ()))). AddressList [0] .tostring (); // Local host IP address str = localhost.substring (0, localhost.lastIndexof ("."));
For (int I = 0; i <255; i ) // Establish 255 thread scan IP {threadMethod = New ThreadStart (LANSEARCHREADMETHED); thread [i] = new thread (threadMethod); thread [i] .name = i. Tostring (); thread [i] .start (); if (! Thread [i] .join (100)) //thread.join (100) I don't know if it is right, I feel like there is no effect {thread [ I] .Abort ();}}
Getlanhost (); Listlanhost ();} ///
} ///