Пример #1
0
        private void cboPoolIp_EditValueChanged(object sender, EventArgs e)
        {
            Class.NW_Dhcp_Ip       cls    = new Class.NW_Dhcp_Ip();
            Class.NW_Dhcp_Customer clscus = new Class.NW_Dhcp_Customer();
            clscus.PoolIp = cboPoolIp.EditValue.ToString();
            DataTable dtcus = clscus.NW_Dhcp_Customer_GetbyPool_MySQL();

            cls.PoolIp = cboPoolIp.EditValue.ToString();
            DataTable dt    = cls.NW_Dhcp_Ip_GetIPbyPool_MySQL();
            string    ip    = "";
            bool      check = false;;

            if (dt.Rows.Count > 0)
            {
                string   range = dt.Rows[0]["RangeIP"].ToString();
                string[] cat   = range.Split(' ');
                if (cat.Length > 1)
                {
                    txtIpAddress.Properties.Items.Clear();
                    string[] temp  = cat[0].Split('.');
                    int      start = 0;
                    int      end   = 0;
                    if (temp.Length > 2)
                    {
                        start = int.Parse(temp[3]);
                    }
                    temp = cat[1].Split('.');
                    if (temp.Length > 2)
                    {
                        end = int.Parse(temp[3]);
                    }

                    for (int i = start; i < end; i++)
                    {
                        ip    = temp[0] + "." + temp[1] + "." + temp[2] + "." + i.ToString();
                        check = false;
                        for (int j = 0; j < dtcus.Rows.Count; j++)
                        {
                            if (ip == dtcus.Rows[j]["IpAddress"].ToString())
                            {
                                check = true;
                            }
                        }
                        if (check == false)
                        {
                            txtIpAddress.Properties.Items.Add(ip);
                        }
                    }
                }
            }
            if (txtIpAddress.Properties.Items.Count > 0)
            {
                txtIpAddress.Text = txtIpAddress.Properties.Items[0].ToString();
            }
            else
            {
                txtIpAddress.Text = "";
            }
        }
Пример #2
0
        private void btnCreateDHCPFile_Click(object sender, EventArgs e)
        {
            try
            {
                if (dt.Rows.Count > 0)
                {
                    if (System.IO.File.Exists(@"dhcpd.conf.temp"))
                    {
                        string txt = System.IO.File.ReadAllText(@"dhcpd.conf.temp");
                        string CPEDynamic = "";
                        string CPEStatic = "";
                        string PoolModem = "";
                        Class.NW_Dhcp_Ip clsIP = new Class.NW_Dhcp_Ip();
                        Class.NW_Dhcp_Customer clsModem = new Class.NW_Dhcp_Customer();
                        DataTable dtCPEDynamic = clsIP.NW_Dhcp_Ip_GetbyCPEDynamic_MySQL();
                        DataTable dtCPEStatic = clsIP.NW_Dhcp_Ip_GetbyCPEStatic_MySQL();
                        DataTable dtPoolModem = clsIP.NW_Dhcp_Ip_GetbyPoolModem_MySQL();
                        #region CPEDynamic
                        for (int i = 0; i < dtCPEDynamic.Rows.Count; i++)
                        {
                            CPEDynamic += "\tsubnet " + dtCPEDynamic.Rows[i]["PoolIp"].ToString() + " netmask " + dtCPEDynamic.Rows[i]["SubnetMask"].ToString() + " {\n" +
                                            "\t\tauthoritative;\n" +
                                            "\t\toption subnet-mask " + dtCPEDynamic.Rows[i]["SubnetMask"].ToString() + ";\n" +
                                            "\t\toption domain-name-servers " + dtCPEDynamic.Rows[i]["Dns"].ToString() + ";\n" +
                                            "\t\toption routers " + dtCPEDynamic.Rows[i]["Router"].ToString() + ";\n" +
                                            "\t\toption broadcast-address " + dtCPEDynamic.Rows[i]["Broadcast"].ToString() + ";\n" +
                                            "\t\tpool {\n" +
                                                "\t\trange " + dtCPEDynamic.Rows[i]["RangeIP"].ToString() + ";\n" +
                                                "\t\t}\n" +
                                            "\t}\n" +
                                            "\tgroup {\n" +
                                                "\t\tuse-host-decl-names on;\n" +
                                            "\t}\n";
                        }
                        #endregion
                        #region CPEStatic
                        for (int i = 0; i < dtCPEStatic.Rows.Count; i++)
                        {
                            clsModem.PoolIp = dtCPEStatic.Rows[i]["PoolIp"].ToString();
                            DataTable dtmodem = clsModem.NW_Dhcp_Customer_GetbyPoolPublic_MySQL();
                            string txtmodem = "";
                            for (int j = 0; j < dtmodem.Rows.Count; j++)
                            {
                                string ipcpe = dtmodem.Rows[j]["IpPublic"].ToString();
                                ipcpe = ipcpe.Replace(":", "-");
                                string reIPcpe = dtmodem.Rows[j]["MacPc"].ToString().Replace(":", "");
                                txtmodem += "\t\t# PC an Modem " + dtmodem.Rows[j]["IpAddress"].ToString() + " " + dtmodem.Rows[j]["Note"].ToString() + " Kunde " + dtmodem.Rows[j]["CustomerCode"].ToString() + " " + dtmodem.Rows[j]["CustomerName"].ToString() + "\n" +
                                            "\t\thost " + ipcpe + " {\n" +
                                                "\t\t\thardware ethernet " + dtmodem.Rows[j]["MacPc"].ToString() + " ;\n" +
                                                "\t\t\tfixed-address " + dtmodem.Rows[j]["IpPublic"].ToString() + ";\n" +
                                                "\t\t\toption host-name 	\"mt" + reIPcpe + "\";\n" +
                                                "\t\t\tddns-hostname 	\"mt" + reIPcpe + "\";\n" +
                                            "\t\t}\n";
                            }

                            CPEStatic += "\tsubnet " + dtCPEStatic.Rows[i]["PoolIp"].ToString() + " netmask " + dtCPEStatic.Rows[i]["SubnetMask"].ToString() + " {\n" +
                                        "\t\tauthoritative;\n" +
                                        "\t\toption subnet-mask " + dtCPEStatic.Rows[i]["SubnetMask"].ToString() + ";\n" +
                                        "\t\toption domain-name-servers " + dtCPEStatic.Rows[i]["Dns"].ToString() + ";\n" +
                                        "\t\toption routers " + dtCPEStatic.Rows[i]["Router"].ToString() + ";\n" +
                                        "\t\toption broadcast-address " + dtCPEStatic.Rows[i]["Broadcast"].ToString() + ";\n" +
                                        "\t}\n" +
                                        "\tgroup {\n" +
                                            "\t\tuse-host-decl-names on;\n" +
                                            txtmodem +
                                        "\t}\n";
                        }
                        #endregion
                        #region CableMode
                        for (int i = 0; i < dtPoolModem.Rows.Count; i++)
                        {
                            clsModem.PoolIp = dtPoolModem.Rows[i]["PoolIp"].ToString();
                            DataTable dtmodem = clsModem.NW_Dhcp_Customer_GetbyPool_MySQL();
                            string listmodem = "";
                            for (int j = 0; j < dtmodem.Rows.Count; j++)
                            {
                                string cm = dtmodem.Rows[j]["MacAddress"].ToString();
                                cm = cm.Replace(":", "");
                                listmodem += "\t\t#  " + dtmodem.Rows[j]["IpAddress"].ToString() + " Kunde " + dtmodem.Rows[j]["CustomerCode"].ToString() + " " + dtmodem.Rows[j]["CustomerName"].ToString() + "\n" +
                                                "\t\thost " + cm + " {\n" +
                                                "\t\t\thardware ethernet " + dtmodem.Rows[j]["MacAddress"].ToString() + " ; \n" +
                                                "\t\t\tfixed-address " + dtmodem.Rows[j]["IpAddress"].ToString() + ";\n" +
                                                "\t\t\toption host-name \"cm" + cm + "\";\n" +
                                                "\t\t\tddns-hostname  \"cm" + cm + "\";\n" +
                                                "\t\t\toption bootfile-name \"" + dtmodem.Rows[j]["Bootfile"].ToString() + "\";\n" +
                                                "\t\t\tfilename \"" + dtmodem.Rows[j]["Bootfile"].ToString() + "\";\n" +
                                                "\t\t}\n";
                            }
                            PoolModem += "\tsubnet " + dtPoolModem.Rows[i]["PoolIp"].ToString() + " netmask " + dtPoolModem.Rows[i]["SubnetMask"].ToString() + " {\n" +
                                        "\t\tauthoritative;\n" +
                                        "\t\toption subnet-mask " + dtPoolModem.Rows[i]["SubnetMask"].ToString() + ";\n" +
                                        "\t\toption routers " + dtPoolModem.Rows[i]["Router"].ToString() + ";\n" +
                                        "\t\toption broadcast-address " + dtPoolModem.Rows[i]["Broadcast"].ToString() + ";\n" +
                                        "\t}\n" +
                                        "\tgroup {\n" +
                                            "\t\tuse-host-decl-names on;\n" +
                                            listmodem +
                                         "\t}\n";

                        }
                        #endregion

                        txt = txt.Replace("<_CPEDynamic>", CPEDynamic);
                        txt = txt.Replace("<_CPEStatic>", CPEStatic);
                        txt = txt.Replace("<_modemip>", PoolModem);

                        System.IO.File.WriteAllText(@"dhcpd.conf", txt);
                    }
                    else
                    {
                        MessageBox.Show("file dhcpd.conf.temp not found!");
                    }
                }
                MessageBox.Show("Hoàn thành tạo file !");
            }
            catch {
                MessageBox.Show("Lỗi tạo file..");
            }

            if (System.IO.File.Exists("dhcpd.conf"))
            {
                frmDHCPService_Template frm = new frmDHCPService_Template("dhcpd.conf");
                frm.ShowDialog();
            }
        }
Пример #3
0
        private void cboPoolIp_EditValueChanged(object sender, EventArgs e)
        {
            Class.NW_Dhcp_Ip cls = new Class.NW_Dhcp_Ip();
            Class.NW_Dhcp_Customer clscus = new Class.NW_Dhcp_Customer();
            clscus.PoolIp = cboPoolIp.EditValue.ToString();
            DataTable dtcus = clscus.NW_Dhcp_Customer_GetbyPool_MySQL();
            cls.PoolIp = cboPoolIp.EditValue.ToString();
            DataTable dt = cls.NW_Dhcp_Ip_GetIPbyPool_MySQL();
            string ip = "";
            bool check = false; ;
            if (dt.Rows.Count > 0)
            {
                string range=dt.Rows[0]["RangeIP"].ToString();
                string[] cat = range.Split(' ');
                if (cat.Length > 1)
                {
                    txtIpAddress.Properties.Items.Clear();
                    string[]temp=cat[0].Split('.');
                    int start = 0;
                    int end = 0;
                    if (temp.Length > 2)
                    {
                         start = int.Parse(temp[3]);
                    }
                    temp = cat[1].Split('.');
                    if (temp.Length > 2)
                    {
                        end = int.Parse(temp[3]);
                    }

                    for (int i=start; i < end; i++)
                    {
                         ip = temp[0] + "." + temp[1] + "." + temp[2] + "." + i.ToString();
                        check = false;
                        for(int j=0;j<dtcus.Rows.Count;j++)
                        {
                            if (ip == dtcus.Rows[j]["IpAddress"].ToString())
                            {
                                check = true;
                            }

                        }
                        if (check == false)
                        {
                            txtIpAddress.Properties.Items.Add(ip);
                        }

                    }
                }
            }
            if (txtIpAddress.Properties.Items.Count > 0)
            {
                txtIpAddress.Text = txtIpAddress.Properties.Items[0].ToString();
            }
            else
            {
                txtIpAddress.Text = "";
            }
        }
Пример #4
0
        private void btnCreateDHCPFile_Click(object sender, EventArgs e)
        {
            try
            {
                if (dt.Rows.Count > 0)
                {
                    if (System.IO.File.Exists(@"dhcpd.conf.temp"))
                    {
                        string                 txt          = System.IO.File.ReadAllText(@"dhcpd.conf.temp");
                        string                 CPEDynamic   = "";
                        string                 CPEStatic    = "";
                        string                 PoolModem    = "";
                        Class.NW_Dhcp_Ip       clsIP        = new Class.NW_Dhcp_Ip();
                        Class.NW_Dhcp_Customer clsModem     = new Class.NW_Dhcp_Customer();
                        DataTable              dtCPEDynamic = clsIP.NW_Dhcp_Ip_GetbyCPEDynamic_MySQL();
                        DataTable              dtCPEStatic  = clsIP.NW_Dhcp_Ip_GetbyCPEStatic_MySQL();
                        DataTable              dtPoolModem  = clsIP.NW_Dhcp_Ip_GetbyPoolModem_MySQL();
                        #region CPEDynamic
                        for (int i = 0; i < dtCPEDynamic.Rows.Count; i++)
                        {
                            CPEDynamic += "\tsubnet " + dtCPEDynamic.Rows[i]["PoolIp"].ToString() + " netmask " + dtCPEDynamic.Rows[i]["SubnetMask"].ToString() + " {\n" +
                                          "\t\tauthoritative;\n" +
                                          "\t\toption subnet-mask " + dtCPEDynamic.Rows[i]["SubnetMask"].ToString() + ";\n" +
                                          "\t\toption domain-name-servers " + dtCPEDynamic.Rows[i]["Dns"].ToString() + ";\n" +
                                          "\t\toption routers " + dtCPEDynamic.Rows[i]["Router"].ToString() + ";\n" +
                                          "\t\toption broadcast-address " + dtCPEDynamic.Rows[i]["Broadcast"].ToString() + ";\n" +
                                          "\t\tpool {\n" +
                                          "\t\trange " + dtCPEDynamic.Rows[i]["RangeIP"].ToString() + ";\n" +
                                          "\t\t}\n" +
                                          "\t}\n" +
                                          "\tgroup {\n" +
                                          "\t\tuse-host-decl-names on;\n" +
                                          "\t}\n";
                        }
                        #endregion
                        #region CPEStatic
                        for (int i = 0; i < dtCPEStatic.Rows.Count; i++)
                        {
                            clsModem.PoolIp = dtCPEStatic.Rows[i]["PoolIp"].ToString();
                            DataTable dtmodem  = clsModem.NW_Dhcp_Customer_GetbyPoolPublic_MySQL();
                            string    txtmodem = "";
                            for (int j = 0; j < dtmodem.Rows.Count; j++)
                            {
                                string ipcpe = dtmodem.Rows[j]["IpPublic"].ToString();
                                ipcpe = ipcpe.Replace(":", "-");
                                string reIPcpe = dtmodem.Rows[j]["MacPc"].ToString().Replace(":", "");
                                txtmodem += "\t\t# PC an Modem " + dtmodem.Rows[j]["IpAddress"].ToString() + " " + dtmodem.Rows[j]["Note"].ToString() + " Kunde " + dtmodem.Rows[j]["CustomerCode"].ToString() + " " + dtmodem.Rows[j]["CustomerName"].ToString() + "\n" +
                                            "\t\thost " + ipcpe + " {\n" +
                                            "\t\t\thardware ethernet " + dtmodem.Rows[j]["MacPc"].ToString() + " ;\n" +
                                            "\t\t\tfixed-address " + dtmodem.Rows[j]["IpPublic"].ToString() + ";\n" +
                                            "\t\t\toption host-name 	\"mt"+ reIPcpe + "\";\n" +
                                            "\t\t\tddns-hostname 	\"mt"+ reIPcpe + "\";\n" +
                                            "\t\t}\n";
                            }

                            CPEStatic += "\tsubnet " + dtCPEStatic.Rows[i]["PoolIp"].ToString() + " netmask " + dtCPEStatic.Rows[i]["SubnetMask"].ToString() + " {\n" +
                                         "\t\tauthoritative;\n" +
                                         "\t\toption subnet-mask " + dtCPEStatic.Rows[i]["SubnetMask"].ToString() + ";\n" +
                                         "\t\toption domain-name-servers " + dtCPEStatic.Rows[i]["Dns"].ToString() + ";\n" +
                                         "\t\toption routers " + dtCPEStatic.Rows[i]["Router"].ToString() + ";\n" +
                                         "\t\toption broadcast-address " + dtCPEStatic.Rows[i]["Broadcast"].ToString() + ";\n" +
                                         "\t}\n" +
                                         "\tgroup {\n" +
                                         "\t\tuse-host-decl-names on;\n" +
                                         txtmodem +
                                         "\t}\n";
                        }
                        #endregion
                        #region CableMode
                        for (int i = 0; i < dtPoolModem.Rows.Count; i++)
                        {
                            clsModem.PoolIp = dtPoolModem.Rows[i]["PoolIp"].ToString();
                            DataTable dtmodem   = clsModem.NW_Dhcp_Customer_GetbyPool_MySQL();
                            string    listmodem = "";
                            for (int j = 0; j < dtmodem.Rows.Count; j++)
                            {
                                string cm = dtmodem.Rows[j]["MacAddress"].ToString();
                                cm         = cm.Replace(":", "");
                                listmodem += "\t\t#  " + dtmodem.Rows[j]["IpAddress"].ToString() + " Kunde " + dtmodem.Rows[j]["CustomerCode"].ToString() + " " + dtmodem.Rows[j]["CustomerName"].ToString() + "\n" +
                                             "\t\thost " + cm + " {\n" +
                                             "\t\t\thardware ethernet " + dtmodem.Rows[j]["MacAddress"].ToString() + " ; \n" +
                                             "\t\t\tfixed-address " + dtmodem.Rows[j]["IpAddress"].ToString() + ";\n" +
                                             "\t\t\toption host-name \"cm" + cm + "\";\n" +
                                             "\t\t\tddns-hostname  \"cm" + cm + "\";\n" +
                                             "\t\t\toption bootfile-name \"" + dtmodem.Rows[j]["Bootfile"].ToString() + "\";\n" +
                                             "\t\t\tfilename \"" + dtmodem.Rows[j]["Bootfile"].ToString() + "\";\n" +
                                             "\t\t}\n";
                            }
                            PoolModem += "\tsubnet " + dtPoolModem.Rows[i]["PoolIp"].ToString() + " netmask " + dtPoolModem.Rows[i]["SubnetMask"].ToString() + " {\n" +
                                         "\t\tauthoritative;\n" +
                                         "\t\toption subnet-mask " + dtPoolModem.Rows[i]["SubnetMask"].ToString() + ";\n" +
                                         "\t\toption routers " + dtPoolModem.Rows[i]["Router"].ToString() + ";\n" +
                                         "\t\toption broadcast-address " + dtPoolModem.Rows[i]["Broadcast"].ToString() + ";\n" +
                                         "\t}\n" +
                                         "\tgroup {\n" +
                                         "\t\tuse-host-decl-names on;\n" +
                                         listmodem +
                                         "\t}\n";
                        }
                        #endregion

                        txt = txt.Replace("<_CPEDynamic>", CPEDynamic);
                        txt = txt.Replace("<_CPEStatic>", CPEStatic);
                        txt = txt.Replace("<_modemip>", PoolModem);

                        System.IO.File.WriteAllText(@"dhcpd.conf", txt);
                    }
                    else
                    {
                        MessageBox.Show("file dhcpd.conf.temp not found!");
                    }
                }
                MessageBox.Show("Hoàn thành tạo file !");
            }
            catch {
                MessageBox.Show("Lỗi tạo file..");
            }

            if (System.IO.File.Exists("dhcpd.conf"))
            {
                frmDHCPService_Template frm = new frmDHCPService_Template("dhcpd.conf");
                frm.ShowDialog();
            }
        }