netmonitor/NetOpenVPNGUI/Runner.cs

59 lines
1.9 KiB
C#
Raw Normal View History

2011-01-27 00:35:09 +01:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Net;
using System.Windows.Forms;
2011-01-27 11:19:41 +01:00
namespace NetOpenVpnGui
2011-01-27 00:35:09 +01:00
{
class Runner
{
private UdpClient net_send;
private IPEndPoint net_send_port;
private UdpClient net_gets;
private IPEndPoint net_gets_port;
2011-01-27 11:19:41 +01:00
public Runner(String p)
2011-01-27 00:35:09 +01:00
{
2011-01-27 11:19:41 +01:00
this.service = p;
this.net_send = new UdpClient();
this.net_send_port = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 34523);
this.net_gets = new UdpClient(34524);
this.net_gets_port = new IPEndPoint(IPAddress.Loopback, 0);
2011-01-27 00:35:09 +01:00
}
2011-01-27 11:19:41 +01:00
public bool run_service()
2011-01-27 00:35:09 +01:00
{
2011-01-27 11:19:41 +01:00
byte[] data = Encoding.UTF8.GetBytes("service start " + this.service);
this.net_send.Send(data, data.Length, this.net_send_port);
bool ret = Boolean.Parse(Encoding.UTF8.GetString(net_gets.Receive(ref net_gets_port)));
if (ret)
return true;
return false;
2011-01-27 00:35:09 +01:00
}
2011-01-27 11:19:41 +01:00
public bool stop_service()
2011-01-27 00:35:09 +01:00
{
2011-01-27 11:19:41 +01:00
byte[] data = Encoding.UTF8.GetBytes("service stop " + this.service);
2011-01-27 00:35:09 +01:00
this.net_send.Send(data, data.Length, this.net_send_port);
2011-01-27 11:19:41 +01:00
bool ret = Boolean.Parse(Encoding.UTF8.GetString(net_gets.Receive(ref net_gets_port)));
if (ret)
return true;
return false;
2011-01-27 00:35:09 +01:00
}
2011-01-27 11:19:41 +01:00
public bool check_service()
2011-01-27 00:35:09 +01:00
{
2011-01-27 11:19:41 +01:00
byte[] data = Encoding.UTF8.GetBytes("service status " + this.service);
2011-01-27 00:35:09 +01:00
this.net_send.Send(data, data.Length, this.net_send_port);
2011-01-27 11:19:41 +01:00
bool ret = Boolean.Parse(Encoding.UTF8.GetString(net_gets.Receive(ref net_gets_port)));
if (ret)
2011-01-27 00:35:09 +01:00
return true;
return false;
}
2011-01-27 11:19:41 +01:00
public string service { get; set; }
2011-01-27 00:35:09 +01:00
}
}