2010-04-21 13:34:01 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.ServiceProcess;
|
|
|
|
|
using System.Text;
|
2010-04-26 12:46:03 +02:00
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Net.Sockets;
|
|
|
|
|
using System.Threading;
|
2010-04-21 13:34:01 +02:00
|
|
|
|
|
|
|
|
|
namespace NetMonitorServer
|
|
|
|
|
{
|
|
|
|
|
public partial class Service1 : ServiceBase
|
|
|
|
|
{
|
2010-04-26 12:46:03 +02:00
|
|
|
|
private Thread ot;
|
2010-04-21 13:34:01 +02:00
|
|
|
|
public Service1()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2010-04-26 12:46:03 +02:00
|
|
|
|
this.ot = new Thread(new ThreadStart(overwatch));
|
|
|
|
|
this.ot.IsBackground = true;
|
|
|
|
|
}
|
|
|
|
|
private static void overwatch()
|
|
|
|
|
{
|
|
|
|
|
UdpClient client = new UdpClient(34523);
|
|
|
|
|
IPEndPoint iep = new IPEndPoint(IPAddress.Loopback, 0);
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
if (Thread.CurrentThread.ThreadState == System.Threading.ThreadState.AbortRequested)
|
|
|
|
|
{
|
|
|
|
|
client.Close();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
byte[] data = client.Receive(ref iep);
|
|
|
|
|
string text = Encoding.UTF8.GetString(data);
|
|
|
|
|
switchCommand(text);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void switchCommand(string data)
|
|
|
|
|
{
|
2010-04-28 16:34:35 +02:00
|
|
|
|
if (data.Substring(0, 3).ToLower() == "net")
|
|
|
|
|
new SetNetworks(data);
|
2010-04-26 12:46:03 +02:00
|
|
|
|
Console.WriteLine(data);
|
2010-04-21 13:34:01 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnStart(string[] args)
|
|
|
|
|
{
|
2010-04-26 12:46:03 +02:00
|
|
|
|
this.ot.Start();
|
2010-04-21 13:34:01 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnStop()
|
|
|
|
|
{
|
2010-04-26 12:46:03 +02:00
|
|
|
|
this.ot.Abort();
|
2010-04-21 13:34:01 +02:00
|
|
|
|
}
|
2010-04-28 16:34:35 +02:00
|
|
|
|
|
|
|
|
|
public void StartServiceConsole(string[] args)
|
|
|
|
|
{
|
|
|
|
|
this.OnStart(args);
|
|
|
|
|
}
|
2010-04-21 13:34:01 +02:00
|
|
|
|
}
|
|
|
|
|
}
|