void NW_Dhcp_Ip_Getlist() { Class.NW_Dhcp_Ip cls = new Class.NW_Dhcp_Ip(); DataTable dt = cls.NW_Dhcp_Ip_Getlist(); gridItem.DataSource = dt; }
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_GetbyPoolPublic_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]["IpPublic"].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 = ""; } }
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 = ""; } }
void NW_Dhcp_Ip_GetbyPoolModem() { Class.NW_Dhcp_Ip clsIP = new Class.NW_Dhcp_Ip(); DataTable dtip = clsIP.NW_Dhcp_Ip_GetbyPoolModem(); cboPoolIp.Properties.DataSource = dtip; cboPoolIp.Properties.DisplayMember = "PoolIp"; cboPoolIp.Properties.ValueMember = "PoolIp"; }
public frmDHCPCustomer_StaticIP(string IPAddress,string Title,string Note) { InitializeComponent(); this.Text = Title; ipaddress = IPAddress; Class.NW_Dhcp_Ip clsIP = new Class.NW_Dhcp_Ip(); DataTable dtip = clsIP.NW_Dhcp_Ip_GetbyCPEStatic_MySQL(); cboPoolIp.Properties.DataSource = dtip; cboPoolIp.Properties.DisplayMember = "PoolIp"; cboPoolIp.Properties.ValueMember = "PoolIp"; txtNote.Text = Note; }
public frmDHCPCustomer_StaticIP(string IPAddress, string Title, string Note) { InitializeComponent(); this.Text = Title; ipaddress = IPAddress; Class.NW_Dhcp_Ip clsIP = new Class.NW_Dhcp_Ip(); DataTable dtip = clsIP.NW_Dhcp_Ip_GetbyCPEStatic_MySQL(); cboPoolIp.Properties.DataSource = dtip; cboPoolIp.Properties.DisplayMember = "PoolIp"; cboPoolIp.Properties.ValueMember = "PoolIp"; txtNote.Text = Note; }
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(); } }
public void Start() { try { IPHostEntry ipHost = Dns.GetHostEntry(Dns.GetHostName()); // IPAddress ipAddr = ipHost.AddressList[3]; //string ip = ""; //for (int i = 1; i < ipHost.AddressList.Length; i++) //{ // ip = ipHost.AddressList[i].ToString(); server.Prefixes.Add("http://" + "101.99.28.148" + ":1111/"); //} // server.Start(); try { server.Start(); //Throws Exception } catch (HttpListenerException ex) { if (ex.Message.Contains("Access is denied")) { return; } else { throw; } } Console.WriteLine("Listening..."); while (true) { HttpListenerContext context = server.GetContext(); HttpListenerResponse response = context.Response; string page = context.Request.Url.ToString(); //page = context.Request.Url.LocalPath; ; // if (page == string.Empty) if (page.Contains("dhcprestart.html")) { string msg = ""; // tao file conf #region Tao file config try { Class.NW_Dhcp_Customer cls = new Class.NW_Dhcp_Customer(); DataTable dt = cls.NW_Dhcp_Customer_Getlist(); 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(); DataTable dtCPEStatic = clsIP.NW_Dhcp_Ip_GetbyCPEStatic(); DataTable dtPoolModem = clsIP.NW_Dhcp_Ip_GetbyPoolModem(); #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]["Range"].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(); 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(); 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 { msg="file dhcpd.conf.temp not found!"; } } msg = "Create file success!"; } catch { msg = "Fail create to file.."; } #endregion #region UploadtoServer if (msg == "Create file success!") { msg += "\r\nTranfer file to SERVER "; Class.App.uploadFile("ftp://101.99.28.152/test/", Application.StartupPath + "/dhcpd.conf", "administrator", "831031"); try { msg += "Ok"; } catch { msg += "Fail"; } } #endregion //write respones byte[] buffer = Encoding.UTF8.GetBytes(msg); response.ContentLength64 = buffer.Length; Stream st = response.OutputStream; st.Write(buffer, 0, buffer.Length); st.Close(); } else { string msg = "Access Deny !"; byte[] buffer = Encoding.UTF8.GetBytes(msg); response.ContentLength64 = buffer.Length; Stream st = response.OutputStream; st.Write(buffer, 0, buffer.Length); st.Close(); } context.Response.Close(); } } catch { Stop(); Start(); } }
public void Start() { try { IPHostEntry ipHost = Dns.GetHostEntry(Dns.GetHostName()); // IPAddress ipAddr = ipHost.AddressList[3]; //string ip = ""; //for (int i = 1; i < ipHost.AddressList.Length; i++) //{ // ip = ipHost.AddressList[i].ToString(); server.Prefixes.Add("http://" + "101.99.28.148" + ":1111/"); //} // server.Start(); try { server.Start(); //Throws Exception } catch (HttpListenerException ex) { if (ex.Message.Contains("Access is denied")) { return; } else { throw; } } Console.WriteLine("Listening..."); while (true) { HttpListenerContext context = server.GetContext(); HttpListenerResponse response = context.Response; string page = context.Request.Url.ToString(); //page = context.Request.Url.LocalPath; ; // if (page == string.Empty) if (page.Contains("dhcprestart.html")) { string msg = ""; // tao file conf #region Tao file config try { Class.NW_Dhcp_Customer cls = new Class.NW_Dhcp_Customer(); DataTable dt = cls.NW_Dhcp_Customer_Getlist(); 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(); DataTable dtCPEStatic = clsIP.NW_Dhcp_Ip_GetbyCPEStatic(); DataTable dtPoolModem = clsIP.NW_Dhcp_Ip_GetbyPoolModem(); #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]["Range"].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(); 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(); 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 { msg = "file dhcpd.conf.temp not found!"; } } msg = "Create file success!"; } catch { msg = "Fail create to file.."; } #endregion #region UploadtoServer if (msg == "Create file success!") { msg += "\r\nTranfer file to SERVER "; Class.App.uploadFile("ftp://101.99.28.152/test/", Application.StartupPath + "/dhcpd.conf", "administrator", "831031"); try { msg += "Ok"; } catch { msg += "Fail"; } } #endregion //write respones byte[] buffer = Encoding.UTF8.GetBytes(msg); response.ContentLength64 = buffer.Length; Stream st = response.OutputStream; st.Write(buffer, 0, buffer.Length); st.Close(); } else { string msg = "Access Deny !"; byte[] buffer = Encoding.UTF8.GetBytes(msg); response.ContentLength64 = buffer.Length; Stream st = response.OutputStream; st.Write(buffer, 0, buffer.Length); st.Close(); } context.Response.Close(); } } catch { Stop(); Start(); } }
void NW_Dhcp_Ip_Getlist() { Class.NW_Dhcp_Ip cls = new Class.NW_Dhcp_Ip(); DataTable dt= cls.NW_Dhcp_Ip_Getlist(); gridItem.DataSource=dt; }
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(); } }