使用asp.net中的web.config中的ipaddress列表检查ip地址

编程入门 行业动态 更新时间:2024-10-14 04:25:22
本文介绍了使用asp中的web.config中的ipaddress列表检查ip地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用Webconfig文件中的IP地址列表作为

I am using list of ip address in my webconfig file as

<appSettings > <add key="RestrictIPAddress" value="192.0.0.110"/> <add key="RestrictIPAddress1" value="192.168.78.0 to 192.168.78.50"/> <add key="RestrictIPAddress2" value ="193.167.89.0 to 193.167.89.50"/> </appSettings>

我想用用户输入的IP地址检查该IP地址.并在我的前端 我正在将按钮功能用作

and I want to check this ip address with user entered ip address. and In my frontend I am using button function as

string RestrictIP = ConfigurationManager.AppSettings["RestrictIPAddress"]; string RestrictIP1 = ConfigurationManager.AppSettings["RestrictIPAddress1"]; string RestrictIP2 = ConfigurationManager.AppSettings["RestrictIPAddress2"]; if ((txtip.Text == RestrictIP1 || txtip.Text ==RestrictIP2 || txtip .Text ==RestrictIP ) && txtuname.Text == "admin" && txtpwd.Text == "admin") { lblmsg.Text = "your login successfully"; Response.Redirect("welcome.aspx"); } else { lblmsg.Text = "your IP address is not registered"; }

它检查单个IP,但不支持其他列表. 在value属性中使用"to"是否正确. 并且请帮助我,我该如何访问这些值? 在此先谢谢您.

It checks single IP but it does not support for other list. Is that correct to use "to" in value attribute. And Please Help me that how Can I access those values? Thanks in advance.

推荐答案

您好, 1)首先使用以下功能创建IP地址列表,以从IP的Web.config中分配IP地址. Hello , 1) First of all Use The Following Function to Create List OF IP ADRESSES B GIving range oF IP''s fron Web.config. private static ArrayList GetIpAdressFromRange(string fromIp, string toIp) { ArrayList ips = new ArrayList(); IPAddress tmpIP = null; //generate only for valid set of ips //Todo: check for toip >fromIp if (IPAddress.TryParse(fromIp, out tmpIP) == true && IPAddress.TryParse(toIp, out tmpIP) == true) { string[] fromOct = fromIp.Split('.'); string[] toOct = toIp.Split('.'); string a = null, b = null, c = null, d = null; int startA = Convert.ToInt32(fromOct[0]); int startB = Convert.ToInt32(fromOct[1]); int startC = 1; int startD = 1; int endA = Convert.ToInt32(toOct[0]); int endB = 255; int endC = 255; int endD = 255; for (int intA = startA; intA <= endA; intA++) { a = intA.ToString(); startB = intA == Convert.ToInt32(fromOct[0]) ? Convert.ToInt32(fromOct[1]) : 1; endB = intA == Convert.ToInt32(toOct[0]) ? Convert.ToInt32(toOct[1]) : 255; for (int intB = startB; intB <= endB; intB++) { b = intB.ToString(); startC = (intA == Convert.ToInt32(fromOct[0])) && (intB == Convert.ToInt32(fromOct[1])) ? Convert.ToInt32(fromOct[2]) : 1; endC = (intA == Convert.ToInt32(toOct[0])) && (intB == Convert.ToInt32(toOct[1])) ? Convert.ToInt32(toOct[2]) : 255; for (int intC = startC; intC <= endC; intC++) { c = intC.ToString(); startD = (intA == Convert.ToInt32(fromOct[0])) && (intB == Convert.ToInt32(fromOct[1])) && (intC == Convert.ToInt32(fromOct[2])) ? Convert.ToInt32(fromOct[3]) : 1; endD = (intA == Convert.ToInt32(toOct[0])) && (intB == Convert.ToInt32(toOct[1])) && (intC == Convert.ToInt32(toOct[2])) ? Convert.ToInt32(toOct[3]) : 255; for (int intD = startD; intD <= endD; intD++) { d = intD.ToString(); ips.Add(a + "." + b + "." + c + "." + d); Console.WriteLine(a + "." + b + "." + c + "." + d); } } } } } return ips; }

2)一旦您获得了Ate限制的IP地址专家,就可以在该列表中搜索Wheather提供的IP IS受到限制. 请参阅以下链接以获取更多信息... www.technosrix/2009/05/how-to-generate-ip-addresses-from-given.html [ ^ ]

2)Once You Will Get The Arralist OF IP adresseses that Ate Restricted you can Just Search in that list Wheather Provided IP IS restricted. Refer Following Link For More Info ... www.technosrix/2009/05/how-to-generate-ip-addresses-from-given.html[^]

更多推荐

使用asp.net中的web.config中的ipaddress列表检查ip地址

本文发布于:2023-11-02 00:23:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550836.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:地址   列表   web   net   asp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!