Erste Funktionierende Version die Netzwerke einstellen kann
This commit is contained in:
parent
890cfc839a
commit
c613dfff9f
@ -38,9 +38,18 @@ namespace NetMonitorClient
|
|||||||
this.sc.setNetworkAuto(adapter);
|
this.sc.setNetworkAuto(adapter);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.sc.setNetworkIp(ip, subnet, gateway);
|
if (ip == "auto")
|
||||||
this.sc.setNetworkDNS(dns);
|
this.sc.setNetworkIpAuto(adapter);
|
||||||
this.sc.setNetworkWINS(wins);
|
else
|
||||||
|
this.sc.setNetworkIp(ip, subnet, gateway, adapter);
|
||||||
|
if(dns == "auto")
|
||||||
|
this.sc.setNetworkDnsAuto(adapter);
|
||||||
|
else
|
||||||
|
this.sc.setNetworkDNS(dns, adapter);
|
||||||
|
if(wins == "auto")
|
||||||
|
this.sc.setNetworkWinsAuto(adapter);
|
||||||
|
else
|
||||||
|
this.sc.setNetworkWINS(wins, adapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,31 +24,107 @@ namespace NetMonitorClient
|
|||||||
this.rep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 34523);
|
this.rep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 34523);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void setNetworkAuto(string networkcard)
|
internal void setNetworkAuto(string adapter)
|
||||||
{
|
{
|
||||||
if (networkcard == null)
|
if (adapter == null)
|
||||||
{
|
{
|
||||||
System.Windows.Forms.MessageBox.Show("Adapter ist not Set!");
|
System.Windows.Forms.MessageBox.Show("Adapter ist not Set!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
byte[] data = Encoding.UTF8.GetBytes("NET AUTO "+networkcard);
|
byte[] data = Encoding.UTF8.GetBytes("NET AUTO "+adapter);
|
||||||
this.client.Send(data, data.Length, this.rep);
|
this.client.Send(data, data.Length, this.rep);
|
||||||
//throw new NotImplementedException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void setNetworkIp(string ip, string subnet, string gateway)
|
internal void setNetworkIp(string ip, string subnet, string gateway, string adapter)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
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)
|
internal void setNetworkDNS(string dns, string adapter)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
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)
|
internal void setNetworkWINS(string wins, string adapter)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,9 +40,9 @@ namespace NetMonitorServer
|
|||||||
|
|
||||||
private static void switchCommand(string data)
|
private static void switchCommand(string data)
|
||||||
{
|
{
|
||||||
|
Console.WriteLine(data);
|
||||||
if (data.Substring(0, 3).ToLower() == "net")
|
if (data.Substring(0, 3).ToLower() == "net")
|
||||||
new SetNetworks(data);
|
new SetNetworks(data);
|
||||||
Console.WriteLine(data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnStart(string[] args)
|
protected override void OnStart(string[] args)
|
||||||
|
@ -11,7 +11,46 @@ namespace NetMonitorServer
|
|||||||
public SetNetworks(string data)
|
public SetNetworks(string data)
|
||||||
{
|
{
|
||||||
if (data.Substring(0, 8).ToLower() == "net auto")
|
if (data.Substring(0, 8).ToLower() == "net auto")
|
||||||
setNetworkAuto(data);
|
this.setNetworkAuto(data);
|
||||||
|
if (data.Substring(0, 6).ToLower() == "net ip")
|
||||||
|
this.setNetworkIp(data);
|
||||||
|
if (data.Substring(0, 7).ToLower() == "net dns")
|
||||||
|
this.setNetworkDns(data);
|
||||||
|
if (data.Substring(0, 8).ToLower() == "net wins")
|
||||||
|
this.setNetworkWins(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setNetworkWins(string data)
|
||||||
|
{
|
||||||
|
String[] par = data.Split(' ');
|
||||||
|
if (par.Length != 4)
|
||||||
|
return;
|
||||||
|
if (par[2].ToLower() == "auto")
|
||||||
|
this.runProgramNetsh("interface ipv4 set winsservers name=\"" + par[3] + "\" source=dhcp");
|
||||||
|
else
|
||||||
|
this.runProgramNetsh("interface ipv4 set winsservers \"" + par[3] + "\" static " + par[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setNetworkDns(string data)
|
||||||
|
{
|
||||||
|
String[] par = data.Split(' ');
|
||||||
|
if (par.Length != 4)
|
||||||
|
return;
|
||||||
|
if (par[2].ToLower() == "auto")
|
||||||
|
this.runProgramNetsh("interface ipv4 set dnsservers name=\"" + par[3] + "\" source=dhcp");
|
||||||
|
else
|
||||||
|
this.runProgramNetsh("interface ipv4 set dnsservers \"" + par[3] + "\" static " + par[2] + " primary");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setNetworkIp(string data)
|
||||||
|
{
|
||||||
|
String[] par = data.Split(' ');
|
||||||
|
if (par.Length != 4 && par.Length != 6)
|
||||||
|
return;
|
||||||
|
if (par[2].ToLower() == "auto")
|
||||||
|
this.runProgramNetsh("interface ipv4 set address name=\"" + par[3] + "\" source=dhcp");
|
||||||
|
else
|
||||||
|
this.runProgramNetsh("interface ipv4 set address \"" + par[5] + "\" static " + par[2] + " " + par[3] + " " + par[4]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setNetworkAuto(string data)
|
private void setNetworkAuto(string data)
|
||||||
@ -19,26 +58,23 @@ namespace NetMonitorServer
|
|||||||
String[] par = data.Split(' ');
|
String[] par = data.Split(' ');
|
||||||
if (par.Length != 3)
|
if (par.Length != 3)
|
||||||
return;
|
return;
|
||||||
Process p1 = new Process();
|
this.runProgramNetsh("interface ipv4 set address name=\""+par[2]+"\" source=dhcp");
|
||||||
p1.StartInfo.Arguments = "interface ipv4 set address name=\""+par[2]+"\" source=dhcp";
|
this.runProgramNetsh("interface ipv4 set dnsservers name=\"" + par[2] + "\" source=dhcp");
|
||||||
p1.StartInfo.FileName = "netsh";
|
this.runProgramNetsh("interface ipv4 set winsservers name=\"" + par[2] + "\" source=dhcp");
|
||||||
p1.Start();
|
}
|
||||||
p1.WaitForExit();
|
|
||||||
Console.WriteLine(p1.ExitCode);
|
|
||||||
|
|
||||||
Process p2 = new Process();
|
private void runProgramNetsh(string args)
|
||||||
p2.StartInfo.Arguments = "interface ipv4 set dnsservers name=\"" + par[2] + "\" source=dhcp";
|
{
|
||||||
p2.StartInfo.FileName = "netsh";
|
Process p = new Process();
|
||||||
p2.Start();
|
p.StartInfo.Arguments = args;
|
||||||
p2.WaitForExit();
|
p.StartInfo.FileName = "netsh";
|
||||||
Console.WriteLine(p2.ExitCode);
|
p.StartInfo.CreateNoWindow = true;
|
||||||
|
p.StartInfo.RedirectStandardOutput = true;
|
||||||
Process p3 = new Process();
|
p.StartInfo.UseShellExecute = false;
|
||||||
p3.StartInfo.Arguments = "interface ipv4 set winsservers name=\"" + par[2] + "\" source=dhcp";
|
p.Start();
|
||||||
p3.StartInfo.FileName = "netsh";
|
string output = p.StandardOutput.ReadToEnd();
|
||||||
p3.Start();
|
p.WaitForExit();
|
||||||
p3.WaitForExit();
|
Console.WriteLine(output.Trim());
|
||||||
Console.WriteLine(p3.ExitCode);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user