2010-06-09 01:38:45 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows.Forms;
|
2010-06-10 00:28:48 +02:00
|
|
|
|
using System.Collections;
|
2010-06-09 01:38:45 +02:00
|
|
|
|
|
|
|
|
|
namespace NetMonitorClient
|
|
|
|
|
{
|
|
|
|
|
public partial class EditNetworks : Form
|
|
|
|
|
{
|
|
|
|
|
public enum Options
|
|
|
|
|
{
|
2010-07-15 02:41:08 +02:00
|
|
|
|
Show,
|
|
|
|
|
Edit
|
2010-06-09 01:38:45 +02:00
|
|
|
|
}
|
|
|
|
|
internal enum RWFlag
|
|
|
|
|
{
|
|
|
|
|
Read,
|
|
|
|
|
Write
|
|
|
|
|
}
|
2010-06-10 00:28:48 +02:00
|
|
|
|
internal enum AMMode
|
|
|
|
|
{
|
|
|
|
|
Auto,
|
|
|
|
|
Manu,
|
|
|
|
|
Disable
|
|
|
|
|
}
|
2010-06-09 01:38:45 +02:00
|
|
|
|
private RWFlag acess;
|
2010-06-10 00:28:48 +02:00
|
|
|
|
private InIReader networkini;
|
2010-06-09 01:38:45 +02:00
|
|
|
|
public EditNetworks(Options option)
|
|
|
|
|
{
|
|
|
|
|
if (option == Options.Show)
|
|
|
|
|
{
|
|
|
|
|
this.acess = RWFlag.Read;
|
|
|
|
|
}
|
2010-07-15 02:41:08 +02:00
|
|
|
|
if (option == Options.Edit)
|
|
|
|
|
{
|
|
|
|
|
this.acess = RWFlag.Write;
|
|
|
|
|
}
|
2010-06-09 01:38:45 +02:00
|
|
|
|
InitializeComponent();
|
2010-06-10 00:28:48 +02:00
|
|
|
|
ReadNetworksSettings();
|
|
|
|
|
SetRWSettings();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetRWSettings()
|
|
|
|
|
{
|
|
|
|
|
if (this.acess == RWFlag.Read)
|
|
|
|
|
{
|
|
|
|
|
this.BoxDns.ReadOnly = true;
|
|
|
|
|
this.BoxGateway.ReadOnly = true;
|
|
|
|
|
this.BoxIpAdresse.ReadOnly = true;
|
|
|
|
|
this.BoxName.ReadOnly = true;
|
|
|
|
|
this.BoxSubnet.ReadOnly = true;
|
|
|
|
|
this.BoxWins.ReadOnly = true;
|
|
|
|
|
this.Text = "Netzwerke Ansehen";
|
|
|
|
|
this.RadioAllAuto.Enabled = false;
|
|
|
|
|
this.RadioAllManu.Enabled = false;
|
|
|
|
|
this.RadioDnsAuto.Enabled = false;
|
|
|
|
|
this.RadioDnsManu.Enabled = false;
|
|
|
|
|
this.RadioIpAuto.Enabled = false;
|
|
|
|
|
this.RadioIpManu.Enabled = false;
|
|
|
|
|
this.RadioWinsAuto.Enabled = false;
|
|
|
|
|
this.RadioWinsManu.Enabled = false;
|
|
|
|
|
}
|
2010-07-15 02:41:08 +02:00
|
|
|
|
if (this.acess == RWFlag.Write)
|
|
|
|
|
{
|
|
|
|
|
this.BoxDns.ReadOnly = false;
|
|
|
|
|
this.BoxGateway.ReadOnly = false;
|
|
|
|
|
this.BoxIpAdresse.ReadOnly = false;
|
|
|
|
|
this.BoxName.ReadOnly = false;
|
|
|
|
|
this.BoxSubnet.ReadOnly = false;
|
|
|
|
|
this.BoxWins.ReadOnly = false;
|
|
|
|
|
this.Text = "Netzwerke Ändern";
|
|
|
|
|
this.RadioAllAuto.Enabled = true;
|
|
|
|
|
this.RadioAllManu.Enabled = true;
|
|
|
|
|
this.RadioDnsAuto.Enabled = true;
|
|
|
|
|
this.RadioDnsManu.Enabled = true;
|
|
|
|
|
this.RadioIpAuto.Enabled = true;
|
|
|
|
|
this.RadioIpManu.Enabled = true;
|
|
|
|
|
this.RadioWinsAuto.Enabled = true;
|
|
|
|
|
this.RadioWinsManu.Enabled = true;
|
|
|
|
|
}
|
2010-06-10 00:28:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ReadNetworksSettings()
|
|
|
|
|
{
|
|
|
|
|
this.networkini = new InIReader("network.ini");
|
|
|
|
|
ArrayList networks = this.networkini.getSections();
|
|
|
|
|
foreach (String net in networks)
|
|
|
|
|
{
|
|
|
|
|
this.NetworksList.Items.Add(net);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void NetworksList_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ListBox Item = (ListBox)sender;
|
|
|
|
|
String name = networkini.getValue(Item.Text, "Name");
|
|
|
|
|
String ip = networkini.getValue(Item.Text, "Ip");
|
|
|
|
|
String subnet = networkini.getValue(Item.Text, "Subnet");
|
|
|
|
|
String gateway = networkini.getValue(Item.Text, "Gateway");
|
|
|
|
|
String dns = networkini.getValue(Item.Text, "Dns");
|
|
|
|
|
String wins = networkini.getValue(Item.Text, "Wins");
|
|
|
|
|
String adapter = networkini.getValue(Item.Text, "Adapter");
|
|
|
|
|
this.BoxName.Text = name;
|
|
|
|
|
if (ip == "auto" && dns == "auto" && wins == "auto")
|
|
|
|
|
{
|
|
|
|
|
this.setAllMode(AMMode.Auto);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2010-06-12 00:20:15 +02:00
|
|
|
|
this.setAllMode(AMMode.Manu);
|
2010-06-10 00:28:48 +02:00
|
|
|
|
if (ip == "auto")
|
|
|
|
|
setIpMode(AMMode.Auto);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
setIpMode(AMMode.Manu);
|
2010-06-12 00:20:15 +02:00
|
|
|
|
this.BoxIpAdresse.Text = ConvIp(ip);
|
2010-06-10 00:28:48 +02:00
|
|
|
|
this.BoxSubnet.Text = ConvSubnet(subnet);
|
2010-06-12 00:20:15 +02:00
|
|
|
|
this.BoxGateway.Text = ConvIp(gateway);
|
2010-06-10 00:28:48 +02:00
|
|
|
|
}
|
|
|
|
|
if (dns == "auto")
|
|
|
|
|
setDnsMode(AMMode.Auto);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
setDnsMode(AMMode.Manu);
|
2010-06-12 00:20:15 +02:00
|
|
|
|
this.BoxDns.Text = ConvIp(dns);
|
2010-06-10 00:28:48 +02:00
|
|
|
|
}
|
|
|
|
|
if (wins == "auto")
|
|
|
|
|
setWinsMode(AMMode.Auto);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
setWinsMode(AMMode.Manu);
|
2010-06-12 00:20:15 +02:00
|
|
|
|
this.BoxWins.Text = ConvIp(wins);
|
2010-06-10 00:28:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-12 00:20:15 +02:00
|
|
|
|
private string ConvIp(string ip)
|
|
|
|
|
{
|
|
|
|
|
String[] ips = ip.Split('.');
|
|
|
|
|
String[] ret = new String[ips.Length];
|
|
|
|
|
for (int i = 0; i < ips.Length;i++)
|
|
|
|
|
{
|
|
|
|
|
ips[i] = int.Parse(ips[i]).ToString("D3");
|
|
|
|
|
}
|
|
|
|
|
return string.Join(".", ips);
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-10 00:28:48 +02:00
|
|
|
|
private string ConvSubnet(string subnet)
|
|
|
|
|
{
|
|
|
|
|
String[] ips = subnet.Split('.');
|
|
|
|
|
String Bits = "";
|
|
|
|
|
foreach (String part in ips)
|
|
|
|
|
{
|
|
|
|
|
Bits += Convert.ToString(byte.Parse(part), 2).PadLeft(8, '0');
|
|
|
|
|
}
|
|
|
|
|
int meng = 0;
|
|
|
|
|
foreach (char bit in Bits)
|
|
|
|
|
{
|
|
|
|
|
if (bit == '1')
|
|
|
|
|
meng++;
|
|
|
|
|
}
|
|
|
|
|
return meng.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setAllMode(AMMode mode)
|
|
|
|
|
{
|
|
|
|
|
if (mode == AMMode.Auto)
|
|
|
|
|
{
|
2010-06-12 00:20:15 +02:00
|
|
|
|
this.RadioAllAuto.Checked = true;
|
|
|
|
|
this.RadioAllManu.Checked = false;
|
2010-06-10 00:28:48 +02:00
|
|
|
|
setIpMode(AMMode.Disable);
|
|
|
|
|
setDnsMode(AMMode.Disable);
|
|
|
|
|
setWinsMode(AMMode.Disable);
|
|
|
|
|
}
|
|
|
|
|
if (mode == AMMode.Manu)
|
|
|
|
|
{
|
2010-06-12 00:20:15 +02:00
|
|
|
|
this.RadioAllManu.Checked = true;
|
|
|
|
|
this.RadioAllAuto.Checked = false;
|
2010-06-10 00:28:48 +02:00
|
|
|
|
setIpMode(AMMode.Manu);
|
|
|
|
|
setDnsMode(AMMode.Manu);
|
|
|
|
|
setWinsMode(AMMode.Manu);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setWinsMode(AMMode mode)
|
|
|
|
|
{
|
|
|
|
|
if (mode == AMMode.Auto)
|
|
|
|
|
{
|
|
|
|
|
this.RadioWinsAuto.Checked = true;
|
|
|
|
|
this.RadioWinsManu.Checked = false;
|
|
|
|
|
this.BoxWins.Enabled = false;
|
|
|
|
|
this.BoxWins.Text = "";
|
|
|
|
|
}
|
|
|
|
|
if (mode == AMMode.Disable)
|
|
|
|
|
{
|
|
|
|
|
this.RadioWinsManu.Checked = false;
|
|
|
|
|
this.RadioWinsAuto.Checked = false;
|
|
|
|
|
this.BoxWins.Enabled = false;
|
|
|
|
|
this.BoxWins.Text = "";
|
|
|
|
|
}
|
|
|
|
|
if (mode == AMMode.Manu)
|
|
|
|
|
{
|
|
|
|
|
this.RadioWinsAuto.Checked = false;
|
|
|
|
|
this.RadioWinsManu.Checked = true;
|
|
|
|
|
this.BoxWins.Enabled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setDnsMode(AMMode mode)
|
|
|
|
|
{
|
|
|
|
|
if (mode == AMMode.Auto)
|
|
|
|
|
{
|
|
|
|
|
this.RadioDnsAuto.Checked = true;
|
|
|
|
|
this.RadioDnsManu.Checked = false;
|
|
|
|
|
this.BoxDns.Enabled = false;
|
|
|
|
|
this.BoxDns.Text = "";
|
|
|
|
|
}
|
|
|
|
|
if (mode == AMMode.Disable)
|
|
|
|
|
{
|
|
|
|
|
this.RadioDnsManu.Checked = false;
|
|
|
|
|
this.RadioDnsAuto.Checked = false;
|
|
|
|
|
this.BoxDns.Enabled = false;
|
|
|
|
|
this.BoxDns.Text = "";
|
|
|
|
|
}
|
|
|
|
|
if (mode == AMMode.Manu)
|
|
|
|
|
{
|
|
|
|
|
this.RadioDnsAuto.Checked = false;
|
|
|
|
|
this.RadioDnsManu.Checked = true;
|
|
|
|
|
this.BoxDns.Enabled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setIpMode(AMMode mode)
|
|
|
|
|
{
|
|
|
|
|
if (mode == AMMode.Auto)
|
|
|
|
|
{
|
|
|
|
|
this.RadioIpAuto.Checked = true;
|
|
|
|
|
this.RadioIpManu.Checked = false;
|
|
|
|
|
this.BoxIpAdresse.Enabled = false;
|
|
|
|
|
this.BoxIpAdresse.Text = "";
|
|
|
|
|
this.BoxSubnet.Enabled = false;
|
|
|
|
|
this.BoxSubnet.Text = "";
|
2010-06-12 00:20:15 +02:00
|
|
|
|
this.BoxGateway.Enabled = false;
|
|
|
|
|
this.BoxGateway.Text = "";
|
2010-06-10 00:28:48 +02:00
|
|
|
|
}
|
|
|
|
|
if (mode == AMMode.Disable)
|
|
|
|
|
{
|
|
|
|
|
this.RadioIpManu.Checked = false;
|
|
|
|
|
this.RadioIpAuto.Checked = false;
|
|
|
|
|
this.BoxIpAdresse.Enabled = false;
|
|
|
|
|
this.BoxIpAdresse.Text = "";
|
|
|
|
|
this.BoxSubnet.Enabled = false;
|
|
|
|
|
this.BoxSubnet.Text = "";
|
2010-06-12 00:20:15 +02:00
|
|
|
|
this.BoxGateway.Enabled = false;
|
|
|
|
|
this.BoxGateway.Text = "";
|
2010-06-10 00:28:48 +02:00
|
|
|
|
}
|
|
|
|
|
if (mode == AMMode.Manu)
|
|
|
|
|
{
|
|
|
|
|
this.RadioIpAuto.Checked = false;
|
|
|
|
|
this.RadioIpManu.Checked = true;
|
|
|
|
|
this.BoxIpAdresse.Enabled = true;
|
|
|
|
|
this.BoxSubnet.Enabled = true;
|
2010-06-12 00:20:15 +02:00
|
|
|
|
this.BoxGateway.Enabled = true;
|
2010-06-10 00:28:48 +02:00
|
|
|
|
}
|
2010-06-09 01:38:45 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|