using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ServiceProcess; using System.Net.Sockets; using System.Net; namespace NetMonitorClient { class ServiceControl { private UdpClient client; private IPEndPoint rep; //remoteEndPoint public ServiceControl(string name) { ServiceController sc = new ServiceController(); sc.ServiceName = name; //if (sc.Status != ServiceControllerStatus.Running) //{ // sc.Start(); //} this.client = new UdpClient(); this.rep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 34523); } internal void setNetworkAuto(string adapter) { if (adapter == null) { System.Windows.Forms.MessageBox.Show("Adapter ist not Set!"); return; } byte[] data = Encoding.UTF8.GetBytes("NET AUTO "+adapter); this.client.Send(data, data.Length, this.rep); } internal void setNetworkIp(string ip, string subnet, string gateway, string adapter) { if (ip == null) { System.Windows.Forms.MessageBox.Show("IP address not Set!"); return; } if (subnet == null) { System.Windows.Forms.MessageBox.Show("Subnet address not Set!"); return; } if (gateway == null) { System.Windows.Forms.MessageBox.Show("Gateway address not Set!"); return; } if (adapter == null) { System.Windows.Forms.MessageBox.Show("Adapter ist not Set!"); return; } byte[] data = Encoding.UTF8.GetBytes("NET IP " + ip + " " + subnet + " " + gateway + " " + adapter); this.client.Send(data, data.Length, this.rep); } internal void setNetworkDNS(string dns, string adapter) { if (dns == null) { System.Windows.Forms.MessageBox.Show("DNS address not Set!"); return; } if (adapter == null) { System.Windows.Forms.MessageBox.Show("Adapter ist not Set!"); return; } byte[] data = Encoding.UTF8.GetBytes("NET DNS " + dns + " " + adapter); this.client.Send(data, data.Length, this.rep); } internal void setNetworkWINS(string wins, string adapter) { if (wins == null) { System.Windows.Forms.MessageBox.Show("WINS address not Set!"); return; } if (adapter == null) { System.Windows.Forms.MessageBox.Show("Adapter ist not Set!"); return; } byte[] data = Encoding.UTF8.GetBytes("NET WINS " + wins + " " + adapter); this.client.Send(data, data.Length, this.rep); } internal void setNetworkIpAuto(string adapter) { if (adapter == null) { System.Windows.Forms.MessageBox.Show("Adapter ist not Set!"); return; } byte[] data = Encoding.UTF8.GetBytes("NET IP AUTO "+adapter); this.client.Send(data, data.Length, this.rep); } internal void setNetworkDnsAuto(string adapter) { if (adapter == null) { System.Windows.Forms.MessageBox.Show("Adapter ist not Set!"); return; } byte[] data = Encoding.UTF8.GetBytes("NET DNS AUTO " + adapter); this.client.Send(data, data.Length, this.rep); } internal void setNetworkWinsAuto(string adapter) { if (adapter == null) { System.Windows.Forms.MessageBox.Show("Adapter ist not Set!"); return; } byte[] data = Encoding.UTF8.GetBytes("NET WINS AUTO " + adapter); this.client.Send(data, data.Length, this.rep); } } }