📄 form1.cs
字号:
this.groupBox2.Location = new System.Drawing.Point(216, 128);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(312, 192);
this.groupBox2.TabIndex = 5;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "查询记录";
//
// groupBox3
//
this.groupBox3.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button2,
this.numericUpDown5,
this.numericUpDown1,
this.numericUpDown2,
this.numericUpDown3,
this.numericUpDown4});
this.groupBox3.Location = new System.Drawing.Point(8, 24);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(200, 96);
this.groupBox3.TabIndex = 9;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "扫描主机";
//
// numericUpDown5
//
this.numericUpDown5.Location = new System.Drawing.Point(152, 64);
this.numericUpDown5.Maximum = new System.Decimal(new int[] {
225,
0,
0,
0});
this.numericUpDown5.Name = "numericUpDown5";
this.numericUpDown5.Size = new System.Drawing.Size(40, 21);
this.numericUpDown5.TabIndex = 8;
this.numericUpDown5.Value = new System.Decimal(new int[] {
225,
0,
0,
0});
//
// numericUpDown1
//
this.numericUpDown1.Location = new System.Drawing.Point(8, 24);
this.numericUpDown1.Maximum = new System.Decimal(new int[] {
225,
0,
0,
0});
this.numericUpDown1.Name = "numericUpDown1";
this.numericUpDown1.Size = new System.Drawing.Size(40, 21);
this.numericUpDown1.TabIndex = 6;
this.numericUpDown1.Value = new System.Decimal(new int[] {
127,
0,
0,
0});
//
// numericUpDown2
//
this.numericUpDown2.Location = new System.Drawing.Point(56, 24);
this.numericUpDown2.Maximum = new System.Decimal(new int[] {
225,
0,
0,
0});
this.numericUpDown2.Name = "numericUpDown2";
this.numericUpDown2.Size = new System.Drawing.Size(40, 21);
this.numericUpDown2.TabIndex = 6;
//
// numericUpDown3
//
this.numericUpDown3.Location = new System.Drawing.Point(104, 24);
this.numericUpDown3.Maximum = new System.Decimal(new int[] {
225,
0,
0,
0});
this.numericUpDown3.Name = "numericUpDown3";
this.numericUpDown3.Size = new System.Drawing.Size(40, 21);
this.numericUpDown3.TabIndex = 7;
//
// numericUpDown4
//
this.numericUpDown4.Location = new System.Drawing.Point(152, 24);
this.numericUpDown4.Maximum = new System.Decimal(new int[] {
225,
0,
0,
0});
this.numericUpDown4.Name = "numericUpDown4";
this.numericUpDown4.Size = new System.Drawing.Size(40, 21);
this.numericUpDown4.TabIndex = 8;
this.numericUpDown4.Value = new System.Decimal(new int[] {
1,
0,
0,
0});
//
// groupBox4
//
this.groupBox4.Controls.AddRange(new System.Windows.Forms.Control[] {
this.textBox3,
this.label3,
this.button3});
this.groupBox4.Location = new System.Drawing.Point(8, 128);
this.groupBox4.Name = "groupBox4";
this.groupBox4.TabIndex = 11;
this.groupBox4.TabStop = false;
this.groupBox4.Text = "远程查询(支持IP和名称)";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(528, 357);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button7,
this.button6,
this.button5,
this.button4,
this.groupBox4,
this.progressBar1,
this.groupBox3,
this.groupBox2,
this.groupBox1});
this.MaximizeBox = false;
this.Name = "Form1";
this.Text = "DNS集成服务系统";
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.numericUpDown5)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown3)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown4)).EndInit();
this.groupBox4.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button2_Click(object sender, System.EventArgs e)
{
//下行构造字符串
string aa=numericUpDown1.Text+"."+numericUpDown2.Text+"."+
numericUpDown3.Text+".";
//下行转换为整型
int i=Int32.Parse(numericUpDown4.Text);
//下行转换为整型
int j=Int32.Parse(numericUpDown5.Text);
//下行设置进度条最小值
progressBar1.Minimum=i;
//下行设置进度条最大值
progressBar1.Maximum=j;
for(i=i;i<=j;i++)
{
string bb=aa+i.ToString();
//下行将字符串转换为IP型
IPAddress myIP = IPAddress.Parse(bb);
try
{
//下行获得主机信息
IPHostEntry myHost = Dns.GetHostByAddress(myIP);
//下行获得主机名并转换为字符串
string cc=myHost.HostName.ToString();
//下行将数据加入到richTextBox1
richTextBox1.AppendText(bb+"-->"+cc+"\r");
}//对应try的“{”
catch(Exception ee){richTextBox1.AppendText(bb+"-->"+ee.Message+"\r");}
//下行设置进度条当前值
progressBar1.Value=i;
}//对应for(i=0;i<j;i++)的“{”
}
private void button1_Click(object sender, System.EventArgs e)
{
IPHostEntry myHost=new IPHostEntry();
try
{
myHost=Dns.GetHostByName(Dns.GetHostName());
textBox1.Text=myHost.HostName.ToString();
richTextBox1.AppendText("本地主机名称-->"+myHost.HostName.ToString()+"\r");
for(int i=0;i<myHost.AddressList.Length;i++)
{
textBox2.Text=myHost.AddressList[i].ToString();
richTextBox1.AppendText("本地主机IP地址-->"+myHost.AddressList[i].ToString()+"\r");
}
}
catch(Exception ee){MessageBox.Show(ee.Message);}
}
private void button3_Click(object sender, System.EventArgs e)
{
IPHostEntry myHost=new IPHostEntry();
myHost=Dns.Resolve(textBox3.Text);
for(int i=0;i<myHost.AddressList.Length;i++)
{
richTextBox1.AppendText(textBox3.Text+"的IP地址-->"+myHost.AddressList[i].ToString()+"\r");
}
}
private void button4_Click(object sender, System.EventArgs e)
{
StreamWriter sw=null;
saveFileDialog1.Filter="文本文件(*.txt)|*.txt|Word文档(*.doc)|*.doc|所有文件(*.*)|*.*";
if(saveFileDialog1.ShowDialog()==DialogResult.OK)
{
try
{
sw=new StreamWriter(saveFileDialog1.FileName,false,System.Text.Encoding.Unicode);
sw.Write(richTextBox1.Text);}
catch(Exception excep){MessageBox.Show(excep.Message);}
finally{if(sw!=null){sw.Close();}
}//对应finally{
} //对应if(saveFileDialog1.ShowDialog()==DialogResult.OK)
}
private void button5_Click(object sender, System.EventArgs e)
{
string aa;
try
{ openFileDialog1.Filter="文本文件(*.txt)|*.txt|Word文档(*.doc)|*.doc|所有文件(*.*)|*.*";
if(openFileDialog1.ShowDialog()==DialogResult.OK)
{
aa=File.OpenText(openFileDialog1.FileName).ReadToEnd();
richTextBox1.AppendText(aa);
File.OpenText(openFileDialog1.FileName).Close();
}
}//try
catch(Exception ee){MessageBox.Show(ee.Message);}
}
private void button7_Click(object sender, System.EventArgs e)
{
richTextBox1.Clear();
}
private void button6_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -