String Proxy,getip;
String Realip;
Realip = request.servervariables["Http_x_forwarded_for"]. ToString ();//return NULL indicates no proxy, otherwise return proxy service IP
Proxy = request.servervariables["REMOTE_ADDR"]. ToString ()/no agent
if (Realip = "")
GetIP = proxy;
Else
GetIP = Realip;
string[] Ip_user_arr = Getip.split ('. ');
Dbreader db = new Dbreader (); Read the IP start and end addresses from the database
DataSet ds = new DataSet ();
DS = db. Select ("SELECT * from Ipcontrol where 1=1");
string[] iPSTAR = new String[ds. Tables[0]. Rows.Count];
string[] Ipend = new String[ds. Tables[0]. Rows.Count];
for (int i = 0; I < ds. Tables[0]. Rows.Count; i++)
{
Ipstar[i] = Sm. Decrypto (ds. Tables[0]. rows[i]["Ipaccessstar"]. ToString ());//Because IP uses the encryption algorithm, it calls SM. Decrpto function
Ipend[i] = Sm. Decrypto (ds. Tables[0]. rows[i]["Ipaccseeend"]. ToString ());
}
if (iPSTAR. Length = = Ipend. Length) && iPSTAR. Length >0)
{
for (int j = 0;j<ipstar. Length; J + +)
{
String ip_start = Ipstar[j];
String ip_end = Ipend[j];
string[] Ip_start_arr = Ip_start. Split ('. ');
string[] Ip_end_arr = ip_end. Split ('. ');
String ip_start_str = "", Ip_end_str = "", Ip_user_str = "";
for (int i = 0;i<4;i++)
{
Ip_start_str + + this.sss (convert.tostring (convert.todouble (ip_start_arr[i))/1000));
Ip_end_str + + this.sss (convert.tostring (convert.todouble (ip_end_arr[i))/1000));
Ip_user_str + + this.sss (convert.tostring (convert.todouble (ip_user_arr[i))/1000));
}
if (convert.todouble (IP_USER_STR) >convert.todouble (ip_end_str) | | Convert.todouble (IP_USER_STR) <convert.todouble (IP_START_STR))
{
Response.Write (' <script language= ' JavaScript ' >alert (' Your IP is not in the Allowed Access IP list. ');</script> ");
}
}
IP meets the criteria when processing
}
Else
{
Processing when the database does not have an IP address filter table
Response.Write (' <script language= ' JavaScript ' >alert (' Your IP is not in the Allowed Access IP list. ');</script> ");
}
Public string sss (string s)
{
int i = s.indexof ('. ');
string temp = s.substring (i+1, s.length-i-1);
while (temp. Length < 3)
{
temp + = "0";
&NBSP;&NBSP;&NBSP}
return temp;
.}