2010-04-16 11:51:46 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
2010-04-26 12:46:03 +02:00
|
|
|
|
using System.ServiceProcess;
|
|
|
|
|
using System.Net.Sockets;
|
|
|
|
|
using System.Net;
|
2010-04-16 11:51:46 +02:00
|
|
|
|
|
2010-04-21 13:48:40 +02:00
|
|
|
|
namespace NetMonitorClient
|
2010-04-16 11:51:46 +02:00
|
|
|
|
{
|
|
|
|
|
class ServiceControl
|
|
|
|
|
{
|
2010-06-02 09:49:33 +02:00
|
|
|
|
private UdpClient net_send;
|
|
|
|
|
private IPEndPoint net_send_port;
|
|
|
|
|
private UdpClient net_gets;
|
|
|
|
|
private IPEndPoint net_gets_port;
|
2010-04-26 12:46:03 +02:00
|
|
|
|
public ServiceControl(string name)
|
2010-04-16 11:51:46 +02:00
|
|
|
|
{
|
2010-04-26 12:46:03 +02:00
|
|
|
|
ServiceController sc = new ServiceController();
|
|
|
|
|
sc.ServiceName = name;
|
|
|
|
|
//if (sc.Status != ServiceControllerStatus.Running)
|
|
|
|
|
//{
|
|
|
|
|
// sc.Start();
|
|
|
|
|
//}
|
2010-06-02 09:49:33 +02:00
|
|
|
|
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);
|
2010-04-16 11:51:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-05-19 09:34:41 +02:00
|
|
|
|
internal bool setNetworkAuto(string adapter)
|
2010-04-16 11:51:46 +02:00
|
|
|
|
{
|
2010-04-28 23:09:00 +02:00
|
|
|
|
if (adapter == null)
|
2010-04-28 16:34:35 +02:00
|
|
|
|
{
|
|
|
|
|
System.Windows.Forms.MessageBox.Show("Adapter ist not Set!");
|
2010-05-19 09:34:41 +02:00
|
|
|
|
return false;
|
2010-04-28 16:34:35 +02:00
|
|
|
|
}
|
2010-04-28 23:09:00 +02:00
|
|
|
|
byte[] data = Encoding.UTF8.GetBytes("NET AUTO "+adapter);
|
2010-06-02 09:49:33 +02:00
|
|
|
|
this.net_send.Send(data, data.Length, this.net_send_port);
|
|
|
|
|
return Boolean.Parse(Encoding.UTF8.GetString(net_gets.Receive(ref net_gets_port)));
|
2010-04-16 11:51:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-05-19 09:34:41 +02:00
|
|
|
|
internal bool setNetworkIp(string ip, string subnet, string gateway, string adapter)
|
2010-04-16 11:51:46 +02:00
|
|
|
|
{
|
2010-04-28 23:09:00 +02:00
|
|
|
|
if (ip == null)
|
|
|
|
|
{
|
|
|
|
|
System.Windows.Forms.MessageBox.Show("IP address not Set!");
|
2010-05-19 09:34:41 +02:00
|
|
|
|
return false;
|
2010-04-28 23:09:00 +02:00
|
|
|
|
}
|
|
|
|
|
if (subnet == null)
|
|
|
|
|
{
|
|
|
|
|
System.Windows.Forms.MessageBox.Show("Subnet address not Set!");
|
2010-05-19 09:34:41 +02:00
|
|
|
|
return false;
|
2010-04-28 23:09:00 +02:00
|
|
|
|
}
|
|
|
|
|
if (gateway == null)
|
|
|
|
|
{
|
|
|
|
|
System.Windows.Forms.MessageBox.Show("Gateway address not Set!");
|
2010-05-19 09:34:41 +02:00
|
|
|
|
return false;
|
2010-04-28 23:09:00 +02:00
|
|
|
|
}
|
|
|
|
|
if (adapter == null)
|
|
|
|
|
{
|
|
|
|
|
System.Windows.Forms.MessageBox.Show("Adapter ist not Set!");
|
2010-05-19 09:34:41 +02:00
|
|
|
|
return false;
|
2010-04-28 23:09:00 +02:00
|
|
|
|
}
|
|
|
|
|
byte[] data = Encoding.UTF8.GetBytes("NET IP " + ip + " " + subnet + " " + gateway + " " + adapter);
|
2010-06-02 09:49:33 +02:00
|
|
|
|
this.net_send.Send(data, data.Length, this.net_send_port);
|
|
|
|
|
return Boolean.Parse(Encoding.UTF8.GetString(net_gets.Receive(ref net_gets_port)));
|
2010-04-16 11:51:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-05-19 09:34:41 +02:00
|
|
|
|
internal bool setNetworkDNS(string dns, string adapter)
|
2010-04-16 11:51:46 +02:00
|
|
|
|
{
|
2010-04-28 23:09:00 +02:00
|
|
|
|
if (dns == null)
|
|
|
|
|
{
|
|
|
|
|
System.Windows.Forms.MessageBox.Show("DNS address not Set!");
|
2010-05-19 09:34:41 +02:00
|
|
|
|
return false;
|
2010-04-28 23:09:00 +02:00
|
|
|
|
}
|
|
|
|
|
if (adapter == null)
|
|
|
|
|
{
|
|
|
|
|
System.Windows.Forms.MessageBox.Show("Adapter ist not Set!");
|
2010-05-19 09:34:41 +02:00
|
|
|
|
return false;
|
2010-04-28 23:09:00 +02:00
|
|
|
|
}
|
|
|
|
|
byte[] data = Encoding.UTF8.GetBytes("NET DNS " + dns + " " + adapter);
|
2010-06-02 09:49:33 +02:00
|
|
|
|
this.net_send.Send(data, data.Length, this.net_send_port);
|
|
|
|
|
return Boolean.Parse(Encoding.UTF8.GetString(net_gets.Receive(ref net_gets_port)));
|
2010-04-16 11:51:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-05-19 09:34:41 +02:00
|
|
|
|
internal bool setNetworkWINS(string wins, string adapter)
|
2010-04-16 11:51:46 +02:00
|
|
|
|
{
|
2010-04-28 23:09:00 +02:00
|
|
|
|
if (wins == null)
|
|
|
|
|
{
|
|
|
|
|
System.Windows.Forms.MessageBox.Show("WINS address not Set!");
|
2010-05-19 09:34:41 +02:00
|
|
|
|
return false;
|
2010-04-28 23:09:00 +02:00
|
|
|
|
}
|
|
|
|
|
if (adapter == null)
|
|
|
|
|
{
|
|
|
|
|
System.Windows.Forms.MessageBox.Show("Adapter ist not Set!");
|
2010-05-19 09:34:41 +02:00
|
|
|
|
return false;
|
2010-04-28 23:09:00 +02:00
|
|
|
|
}
|
|
|
|
|
byte[] data = Encoding.UTF8.GetBytes("NET WINS " + wins + " " + adapter);
|
2010-06-02 09:49:33 +02:00
|
|
|
|
this.net_send.Send(data, data.Length, this.net_send_port);
|
|
|
|
|
return Boolean.Parse(Encoding.UTF8.GetString(net_gets.Receive(ref net_gets_port)));
|
2010-04-28 23:09:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-05-19 09:34:41 +02:00
|
|
|
|
internal bool setNetworkIpAuto(string adapter)
|
2010-04-28 23:09:00 +02:00
|
|
|
|
{
|
|
|
|
|
if (adapter == null)
|
|
|
|
|
{
|
|
|
|
|
System.Windows.Forms.MessageBox.Show("Adapter ist not Set!");
|
2010-05-19 09:34:41 +02:00
|
|
|
|
return false;
|
2010-04-28 23:09:00 +02:00
|
|
|
|
}
|
|
|
|
|
byte[] data = Encoding.UTF8.GetBytes("NET IP AUTO "+adapter);
|
2010-06-02 09:49:33 +02:00
|
|
|
|
this.net_send.Send(data, data.Length, this.net_send_port);
|
|
|
|
|
return Boolean.Parse(Encoding.UTF8.GetString(net_gets.Receive(ref net_gets_port)));
|
2010-04-28 23:09:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-05-19 09:34:41 +02:00
|
|
|
|
internal bool setNetworkDnsAuto(string adapter)
|
2010-04-28 23:09:00 +02:00
|
|
|
|
{
|
|
|
|
|
if (adapter == null)
|
|
|
|
|
{
|
|
|
|
|
System.Windows.Forms.MessageBox.Show("Adapter ist not Set!");
|
2010-05-19 09:34:41 +02:00
|
|
|
|
return false;
|
2010-04-28 23:09:00 +02:00
|
|
|
|
}
|
|
|
|
|
byte[] data = Encoding.UTF8.GetBytes("NET DNS AUTO " + adapter);
|
2010-06-02 09:49:33 +02:00
|
|
|
|
this.net_send.Send(data, data.Length, this.net_send_port);
|
|
|
|
|
return Boolean.Parse(Encoding.UTF8.GetString(net_gets.Receive(ref net_gets_port)));
|
2010-04-28 23:09:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
2010-05-19 09:34:41 +02:00
|
|
|
|
internal bool setNetworkWinsAuto(string adapter)
|
2010-04-28 23:09:00 +02:00
|
|
|
|
{
|
|
|
|
|
if (adapter == null)
|
|
|
|
|
{
|
|
|
|
|
System.Windows.Forms.MessageBox.Show("Adapter ist not Set!");
|
2010-05-19 09:34:41 +02:00
|
|
|
|
return false;
|
2010-04-28 23:09:00 +02:00
|
|
|
|
}
|
|
|
|
|
byte[] data = Encoding.UTF8.GetBytes("NET WINS AUTO " + adapter);
|
2010-06-02 09:49:33 +02:00
|
|
|
|
this.net_send.Send(data, data.Length, this.net_send_port);
|
|
|
|
|
return Boolean.Parse(Encoding.UTF8.GetString(net_gets.Receive(ref net_gets_port)));
|
2010-04-16 11:51:46 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|