71 lines
2.3 KiB
C#
71 lines
2.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using System.Net.NetworkInformation;
|
|
using System.Threading;
|
|
|
|
namespace AGVSystem
|
|
{
|
|
public partial class APTest : Form
|
|
{
|
|
private ClsDBConn_sql db = new ClsDBConn_sql();
|
|
private System.Data.DataSet ds = new System.Data.DataSet();
|
|
private Ping ping = new Ping();
|
|
public APTest()
|
|
{
|
|
InitializeComponent();
|
|
ds = db.connDt("select id as 编号, ipaddress as ip地址 , ssid ,'' as 网络状态 from AP_Site");
|
|
if (ds.Tables.Count > 0)
|
|
{
|
|
dataGridView1.DataSource = ds.Tables[0];
|
|
}
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
button1.Enabled = false;
|
|
Thread newth = new Thread(pingnet);
|
|
newth.Start();
|
|
}
|
|
|
|
private delegate void PingNet();
|
|
private void pingnet()
|
|
{
|
|
if (InvokeRequired)
|
|
{
|
|
this.Invoke(new PingNet(pingnet));
|
|
}
|
|
else
|
|
{
|
|
if (dataGridView1.RowCount > 0)
|
|
{
|
|
for (int row = 0; row < dataGridView1.RowCount; row++)
|
|
{
|
|
try
|
|
{
|
|
if (ping.Send(dataGridView1.Rows[row].Cells["ip地址"].Value.ToString(),1000).Status == IPStatus.Success)
|
|
{
|
|
dataGridView1.Rows[row].Cells["网络状态"].Value = "[" + DateTime.Now.ToLongTimeString() + "]:ok";
|
|
}
|
|
else
|
|
{
|
|
dataGridView1.Rows[row].Cells["网络状态"].Value = "[" + DateTime.Now.ToLongTimeString() + "]:网络异常";
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
dataGridView1.Rows[row].Cells["网络状态"].Value = "[" + DateTime.Now.ToLongTimeString() + "]:网络异常";
|
|
}
|
|
}
|
|
button1.Enabled = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|