using System;
using System.Collections.Generic;
using
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Text;
using System.Threading;
using System.Windows.Forms;
namespace WindwosLink
{
public partial class Form1 : Form
{
public static int updatetime;
public static bool fay = true;
public Thread thread;
public Form1()
{
InitializeComponent();
Button.CheckForIllegalCrossThreadCalls = false;
toolStripStatusLabel1.Text = "登陆时间:"+DateTime.Now.ToString();
toolStripStatusLabel2.Text = "技术支持QQ:492581728";
}
private void btnstart_Click(object sender, EventArgs e)
{
thread = new Thread(Deal);
thread.Start();
}
public void Deal()
{
btnstart.Enabled = false;
btnstop.Enabled = true;
updatetime = DateTime.Now.Minute;
while (fay)
{
Thread.Sleep(Convert.ToInt32(tbtime.Text.Trim()) * 60);
int newtime = DateTime.Now.Minute;
int result = newtime - updatetime;
if (result > Convert.ToInt32(tbtime.Text.Trim()))
{
CmdPing(tbip.Text.Trim());
}
if (result > 0)
{
CmdPing(tbip.Text.Trim());
updatetime = newtime;
}
}
}
//string ip = "211.102.90.6";
//string strRst = CmdPing(ip);
//Console.WriteLine(strRst);
//Console.ReadLine();
private void CmdPing(string strIp)
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
string pingrst;
p.Start();
p.StandardInput.WriteLine("ping -n 1 " + strIp);
p.StandardInput.WriteLine("exit");
string strRst = p.StandardOutput.ReadToEnd();
int abc = strRst.IndexOf("(0% 丢失)");
if (strRst.IndexOf("(0% 丢失)") != -1)
pingrst = "连接";
else if (strRst.IndexOf("Destination host unreachable.") != -1)
pingrst = "无法到达目的主机";
else if (strRst.IndexOf("请求超时。") != -1)
{
pingrst = "超时";
btnstart.Enabled = true;
btnstop.Enabled = false;
labmessage.Text = "请求超时,请尽快处理!!!";
labmessage.ForeColor = Color.Red;
fay = false;
bool result = PostMsgHelper.sendSms(tbphone.Text.Trim(), "您的服务器IP是:" + tbip.Text + "" + pingrst + "");
thread.Abort();
//MessageBox.Show("当前监控的服务器出现异常!!!");
}
else if (strRst.IndexOf("Unknown host") != -1)
pingrst = "无法解析主机";
else
pingrst = strRst;
p.Close();
//return pingrst;
}