178 lines
6.3 KiB
C#
178 lines
6.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace NetMonitorClient
|
|
{
|
|
public class Networksetter
|
|
{
|
|
private ServiceControl sc;
|
|
private InIReader networkini;
|
|
private string net_name;
|
|
private List<string> loglist;
|
|
|
|
private bool Pstatus;
|
|
private string Pname;
|
|
private string Ptext;
|
|
private enum netsetter
|
|
{
|
|
Auto,
|
|
IpAuto,
|
|
Ip,
|
|
DnsAuto,
|
|
Dns,
|
|
WinsAuto,
|
|
Wins
|
|
}
|
|
public Networksetter(string name, InIReader ini, ServiceControl serv)
|
|
{
|
|
this.net_name = name;
|
|
this.networkini = ini;
|
|
loglist = new List<string>();
|
|
this.sc = serv;
|
|
}
|
|
public void setNetwork()
|
|
{
|
|
String name = networkini.getValue(net_name, "Name");
|
|
String ip = networkini.getValue(net_name, "Ip");
|
|
String subnet = networkini.getValue(net_name, "Subnet");
|
|
String gateway = networkini.getValue(net_name, "Gateway");
|
|
String dns = networkini.getValue(net_name, "Dns");
|
|
String wins = networkini.getValue(net_name, "Wins");
|
|
String adapter = networkini.getValue(net_name, "Adapter");
|
|
|
|
if (ip == "auto" && dns == "auto" && wins == "auto")
|
|
{
|
|
setNetworkAuto(adapter, name);
|
|
}
|
|
else
|
|
{
|
|
if (ip == "auto")
|
|
setNetworkIpAuto(adapter, name);
|
|
else
|
|
setNetworkIp(ip, subnet, gateway, adapter, name);
|
|
if (dns == "auto")
|
|
setNetworkDnsAuto(adapter, name);
|
|
else
|
|
setNetworkDns(dns, adapter, name);
|
|
if (wins == "auto")
|
|
setNetworkWinsAuto(adapter, name);
|
|
else
|
|
setNetworkWins(wins, adapter, name);
|
|
}
|
|
}
|
|
private void setNetworkAuto(string adapter, string name)
|
|
{
|
|
setNetwork(netsetter.Auto, null, null, null, adapter, name, null, null);
|
|
}
|
|
private void setNetworkIpAuto(string adapter, string name)
|
|
{
|
|
setNetwork(netsetter.IpAuto, null, null, null, adapter, name, null, null);
|
|
}
|
|
private void setNetworkIp(string ip, string subnet, string gateway, string adapter, string name)
|
|
{
|
|
setNetwork(netsetter.Ip, ip, subnet, gateway, adapter, name, null, null);
|
|
}
|
|
private void setNetworkDnsAuto(string adapter, string name)
|
|
{
|
|
setNetwork(netsetter.DnsAuto, null, null, null, adapter, name, null, null);
|
|
}
|
|
private void setNetworkDns(string dns, string adapter, string name)
|
|
{
|
|
setNetwork(netsetter.Dns, null, null, null, adapter, name, dns, null);
|
|
}
|
|
private void setNetworkWinsAuto(string adapter, string name)
|
|
{
|
|
setNetwork(netsetter.WinsAuto, null, null, null, adapter, name, null, null);
|
|
}
|
|
private void setNetworkWins(string wins, string adapter, string name)
|
|
{
|
|
setNetwork(netsetter.Wins, null, null, null, adapter, name, null, wins);
|
|
}
|
|
private void setNetwork(netsetter option, string ip, string subnet, string gateway, string adapter, string name, string dns, string wins)
|
|
{
|
|
bool status = false;
|
|
List<string> text = new List<string>();
|
|
if (option == netsetter.Ip)
|
|
{
|
|
text.Add("Ip: " + ip + ";Subnet: " + subnet + ";Gateway: " + gateway);
|
|
loglist.Add("Gesendet: " + text);
|
|
System.Windows.Forms.Application.DoEvents();
|
|
status = this.sc.setNetworkIp(ip, subnet, gateway, adapter);
|
|
}
|
|
if (option == netsetter.Auto)
|
|
{
|
|
text.Add("Netzwerk auf Auto");
|
|
loglist.Add("Gesendet: " + text);
|
|
System.Windows.Forms.Application.DoEvents();
|
|
status = this.sc.setNetworkAuto(adapter);
|
|
}
|
|
if (option == netsetter.IpAuto)
|
|
{
|
|
text.Add("Ip auf Auto");
|
|
loglist.Add("Gesendet: " + text);
|
|
System.Windows.Forms.Application.DoEvents();
|
|
status = this.sc.setNetworkIpAuto(adapter);
|
|
}
|
|
if (option == netsetter.DnsAuto)
|
|
{
|
|
text.Add("Dns auf Auto");
|
|
loglist.Add("Gesendet: " + text);
|
|
System.Windows.Forms.Application.DoEvents();
|
|
status = this.sc.setNetworkDnsAuto(adapter);
|
|
}
|
|
if (option == netsetter.WinsAuto)
|
|
{
|
|
text.Add("Wins auf Auto");
|
|
loglist.Add("Gesendet: " + text);
|
|
System.Windows.Forms.Application.DoEvents();
|
|
status = this.sc.setNetworkWinsAuto(adapter);
|
|
}
|
|
if (option == netsetter.Dns)
|
|
{
|
|
text.Add("Dns: " + dns);
|
|
loglist.Add("Gesendet: " + text);
|
|
status = this.sc.setNetworkDNS(dns, adapter);
|
|
}
|
|
if (option == netsetter.Wins)
|
|
{
|
|
text.Add("Wins: " + wins);
|
|
loglist.Add("Gesendet: " + text);
|
|
System.Windows.Forms.Application.DoEvents();
|
|
status = this.sc.setNetworkWINS(wins, adapter);
|
|
}
|
|
loglist.Add("Antwort: " + ((status) ? "Ok" : "Fehler"));
|
|
System.Windows.Forms.Application.DoEvents();
|
|
setPopup(status, name, String.Join("\n",text.ToArray()));
|
|
}
|
|
|
|
private void setPopup(bool status, string name, string text)
|
|
{
|
|
this.Pstatus = status;
|
|
this.Pname = name;
|
|
this.Ptext = text;
|
|
}
|
|
|
|
internal bool getPopupBool()
|
|
{
|
|
return this.Pstatus;
|
|
}
|
|
|
|
internal string getPopupTitel()
|
|
{
|
|
return this.Pname;
|
|
}
|
|
|
|
internal string getPopupText()
|
|
{
|
|
return this.Ptext;
|
|
}
|
|
|
|
public List<string> getLog()
|
|
{
|
|
return this.loglist;
|
|
}
|
|
}
|
|
}
|