📄 form1.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.NetworkInformation;
using System.Data.SqlClient;
namespace PingDomain
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Ping(textBox1.Text);
}
private void Ping(string IP)
{
Ping pingSender = new Ping();
PingOptions options = new PingOptions();
options.DontFragment = true;
string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
byte[] buffer = Encoding.ASCII.GetBytes(data);
int timeout = 120;
PingReply reply = pingSender.Send(IP, timeout, buffer, options);
listBox1.Items.Clear();
if (reply.Status != IPStatus.Success)
{
listBox1.Items.Add("失败============");
//listBox1.Items.Add(reply.Address.ToString());
listBox1.Items.Add(reply.Status.ToString());
textBox5.Text = "";
return;
}
listBox1.Items.Add("成功============");
listBox1.Items.Add(reply.Address.ToString());
textBox5.Text = reply.Address.ToString();
////显示结果
//System.Net.Sockets.AddressFamily AF = reply.Address.AddressFamily;
}
private void button2_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
}
private void button3_Click(object sender, EventArgs e)
{
//连接
string connectstr =
"Data Source=" + textBox5.Text + ";Initial Catalog=" + textBox4.Text + ";Persist Security Info=True;User ID=" + textBox2.Text + ";password=" + textBox3.Text + ";";
SqlConnection cn = new SqlConnection(connectstr);
cn.Open();
listBox1.Items.Add("连接成功============");
listBox1.Items.Add( textBox5.Text);
}
private void button4_Click(object sender, EventArgs e)
{
PingReply reply = Ping_GetServerName.GetPingReply(textBox1.Text);
listBox1.Items.Clear();
if (reply.Status != IPStatus.Success)
{
listBox1.Items.Add("失败============");
//listBox1.Items.Add(reply.Address.ToString());
listBox1.Items.Add(reply.Status.ToString());
textBox5.Text = "";
return;
}
listBox1.Items.Add("成功============");
listBox1.Items.Add(reply.Address.ToString());
textBox5.Text = reply.Address.ToString();
}
private void button5_Click(object sender, EventArgs e)
{
listBox1.Items.Add("成功============");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -