天津投入产出系统后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

87 lines
3.0 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Configuration;
using QMAPP.FJC.BLL.Basic;
using QMAPP.FJC.Entity.Basic;
using System.Data;
namespace AutoFileCopyNet
{
public class NetworkMonitor
{
[DllImport("wininet.dll")]
private extern static bool InternetGetConnectedState(out int connectionDescription, int reservedValue);
//检测本机是否连接到互联网
private bool IsConnected()
{
int I = 0;
bool state = InternetGetConnectedState(out I, 0);
return state;
}
private string PingResult(string ip)
{
try
{
System.Net.NetworkInformation.Ping p = new System.Net.NetworkInformation.Ping();
System.Net.NetworkInformation.PingOptions options = new System.Net.NetworkInformation.PingOptions();
options.DontFragment = true;
string data = "12345678901234567890123456789012";
byte[] buffer = Encoding.ASCII.GetBytes(data);
int timeout = 1000;
System.Net.NetworkInformation.PingReply reply = p.Send(ip, timeout, buffer, options);
//PingTime = int.Parse(reply.RoundtripTime.ToString());
return reply.Status.ToString();
}
catch (Exception ex)
{
throw ex;
}
}
// public int MonitorLever;
public void MonitoringStart()
{
try
{
lock (this)
{
//MonitorLever = int.Parse(ConfigurationSettings.AppSettings["MonitorLever"].ToString());
MachineInfoBLL bllFisOrder = new MachineInfoBLL();
List<MachineInfo> list = bllFisOrder.GetAllList(new MachineInfo());
foreach (MachineInfo row in list)
{
string strip = row.IPADDRESS.ToString();
string strname = row.MACHINENAME.ToString();
string constatus = PingResult(strip);
if (constatus != "Success")
{
string eeror = strname + "(" + strip + ")" + "网络ping不通";
//插入报警信息
//DataTable wtb = bllFisOrder.QueryWaring(strip);
//if (wtb.Rows.Count == 0)
//{
// bllFisOrder.InsertWaring(eeror, strip);
//}
//else
//{
// bllFisOrder.UpdateWaring(strip);
//}
}
}
}
}
catch (Exception ex)
{
}
finally
{
}
}
}
}