网站后台扫描指定ip,并将状态写入数据库
1<%@ Application Language="C#" %>
2<%@ Import Namespace="System.Threading"%>
3<%@ Import Namespace="System.Data"%>
4
5<script runat="server">
6
7 void Application_Start(object sender, EventArgs e)
8 {
9 //在应用程序启动时运行的代码
10 System.Timers.Timer myTimer = new System.Timers.Timer(60000);
11 myTimer.Elapsed += new System.Timers.ElapsedEventHandler(OnTimedEvent);
12 myTimer.Interval = 60000;
13 myTimer.Enabled = true;
14 }
15
16 private static void OnTimedEvent(object source, System.Timers.ElapsedEventArgs e)
17 {
18 WebService command = new WebService();
19 int row_count = Convert.ToInt32(command.Find("select count(*) as row_count from ping").ToString());
20 WebService sql = new WebService();
21 string ipa = "";
22
23
24 ScanWebTableAdapters.PINGTableAdapter da = new ScanWebTableAdapters.PINGTableAdapter();
25 ScanWeb.PINGDataTable dt = da.GetData();
26 foreach (DataRow myRow in dt.Rows)
27 {
28 ipa = myRow["ip"].ToString();
29 ThreadPool.QueueUserWorkItem(new WaitCallback(checkipstate), new TcpClientConnector.CheckIP(ipa));
30 }
31 }
32
33 private static void checkipstate(object checkIP)
34 {
35 //检查该ip状态
36 TcpClientConnector.CheckIP ip = (TcpClientConnector.CheckIP)checkIP;
37 TcpClientConnector.Check(ip);
38 string state = "";
39 string image = "";
40 string point_brush = "";
41 string tracert = "";
42 traceroute tr = new traceroute();
43 tracert = tr.tracert(ip.Hostname.ToString());
44 if (ip.state)
45 {
46 state = "开启";
47 image = "img/1.gif";
48 point_brush = "Brush_province_enable";
49 }
50 else
51 {
52 state = "关闭";
53 image = "img/0.png";
54 point_brush = "Brush_province_disable";
55 }
56 //写数据库
57 WebService sql = new WebService();
58 string sqlcmd = "update ping set remark='" + state + "',img='" + image + "',scantime='" + DateTime.Now.ToString() + "',point_brush='" + point_brush + "',tracert='"+tracert+"' where ip='" + ip.Hostname + "'";
59 try
60 {
61 sql.ExcuteSql(sqlcmd);
62 }
63 catch { }
64 }
65
66 void Application_End(object sender, EventArgs e)
67 {
68 //在应用程序关闭时运行的代码
69
70 }
71
72 void Application_Error(object sender, EventArgs e)
73 {
74 //在出现未处理的错误时运行的代码
75
76 }
77
78 void Session_Start(object sender, EventArgs e)
79 {
80 //在新会话启动时运行的代码
81
82 }
83
84 void Session_End(object sender, EventArgs e)
85 {
86 //在会话结束时运行的代码。
87 // 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为
88 // InProc 时,才会引发 Session_End 事件。如果会话模式
89 //设置为 StateServer 或 SQLServer,则不会引发该事件。
90
91 }
92
93</script>
94
2<%@ Import Namespace="System.Threading"%>
3<%@ Import Namespace="System.Data"%>
4
5<script runat="server">
6
7 void Application_Start(object sender, EventArgs e)
8 {
9 //在应用程序启动时运行的代码
10 System.Timers.Timer myTimer = new System.Timers.Timer(60000);
11 myTimer.Elapsed += new System.Timers.ElapsedEventHandler(OnTimedEvent);
12 myTimer.Interval = 60000;
13 myTimer.Enabled = true;
14 }
15
16 private static void OnTimedEvent(object source, System.Timers.ElapsedEventArgs e)
17 {
18 WebService command = new WebService();
19 int row_count = Convert.ToInt32(command.Find("select count(*) as row_count from ping").ToString());
20 WebService sql = new WebService();
21 string ipa = "";
22
23
24 ScanWebTableAdapters.PINGTableAdapter da = new ScanWebTableAdapters.PINGTableAdapter();
25 ScanWeb.PINGDataTable dt = da.GetData();
26 foreach (DataRow myRow in dt.Rows)
27 {
28 ipa = myRow["ip"].ToString();
29 ThreadPool.QueueUserWorkItem(new WaitCallback(checkipstate), new TcpClientConnector.CheckIP(ipa));
30 }
31 }
32
33 private static void checkipstate(object checkIP)
34 {
35 //检查该ip状态
36 TcpClientConnector.CheckIP ip = (TcpClientConnector.CheckIP)checkIP;
37 TcpClientConnector.Check(ip);
38 string state = "";
39 string image = "";
40 string point_brush = "";
41 string tracert = "";
42 traceroute tr = new traceroute();
43 tracert = tr.tracert(ip.Hostname.ToString());
44 if (ip.state)
45 {
46 state = "开启";
47 image = "img/1.gif";
48 point_brush = "Brush_province_enable";
49 }
50 else
51 {
52 state = "关闭";
53 image = "img/0.png";
54 point_brush = "Brush_province_disable";
55 }
56 //写数据库
57 WebService sql = new WebService();
58 string sqlcmd = "update ping set remark='" + state + "',img='" + image + "',scantime='" + DateTime.Now.ToString() + "',point_brush='" + point_brush + "',tracert='"+tracert+"' where ip='" + ip.Hostname + "'";
59 try
60 {
61 sql.ExcuteSql(sqlcmd);
62 }
63 catch { }
64 }
65
66 void Application_End(object sender, EventArgs e)
67 {
68 //在应用程序关闭时运行的代码
69
70 }
71
72 void Application_Error(object sender, EventArgs e)
73 {
74 //在出现未处理的错误时运行的代码
75
76 }
77
78 void Session_Start(object sender, EventArgs e)
79 {
80 //在新会话启动时运行的代码
81
82 }
83
84 void Session_End(object sender, EventArgs e)
85 {
86 //在会话结束时运行的代码。
87 // 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为
88 // InProc 时,才会引发 Session_End 事件。如果会话模式
89 //设置为 StateServer 或 SQLServer,则不会引发该事件。
90
91 }
92
93</script>
94