小弟想实现这样的一个功能, 就是只运行某段IP访问我的窗体,只要IP不在这个范围就不可以。现在我只能是指定某个IP,而不是某段。怎样才能实现 比如10.139.xxx.xxx 这样的一个范围呢。
private void button1_Click(object sender, EventArgs e)
        {
            string sqlserver = "Data Source=localhost\\SQLEXPRESS;Initial Catalog=stu;Integrated Security=True";
            string sql = "select * from student_form where stu_id='" + textBox1.Text + "'";
            IPAddress ipaddress = new System.Net.IPAddress(Dns.GetHostByName(Dns.GetHostName()).AddressList[0].Address);
            string ip_add = ipaddress.ToString();
            string myip = "10.139.28.22";
            // if (textBox1.Text == "")
            if (ip_add != myip)
            {
                MessageBox.Show("Sorry, come to the lab.");
            }
            else
            {
                using (SqlConnection con = new SqlConnection(sqlserver))
                {
                    con.Open();                    SqlCommand cmd = new SqlCommand(sql, con);
                    SqlDataReader sdr = cmd.ExecuteReader();
                    sdr.Read();
                    if (sdr.HasRows)
                    {
                        sdr.Close();
                        MessageBox.Show("login successfully!", "", MessageBoxButtons.OK);                        Form2 f2 = new Form2(this);
                        f2.Show();                    }
                    else
                    {
                        sdr.Close();
                        MessageBox.Show("sorry,unsuccessful login", "", MessageBoxButtons.OK);
                    }
                }
            }
        }