Check IP Range
Check IP Range using asp.net code sample
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace IpBlocker.IPCheckers
{
public class IpRangeChecker : IChcker
{
public string[] IpRanges { get; set; }
public string Access { get; set; }
public IpRangeChecker(string value, string access)
{
this.IpRanges = value.Split(',');
this.Access = access;
}
#region IChcker Members
public bool CanBlockIp(string ipAddress)
{
bool result = false;
foreach (string ipRange in IpRanges)
{
string[] ipValues = ipRange.Split(';');
if (string.Compare(this.Access, "granted", true) == 0)
{
if ((IpCompare.IsGreaterOrEqual(ipAddress, ipValues[0])) &&
(IpCompare.IsLessOrEqual(ipAddress, ipValues[1])))
{
result = false;
break;
}
else
{
result = true;
}
}
else if (string.Compare(this.Access, "denied", true) == 0)
{
if ((IpCompare.IsGreaterOrEqual(ipAddress, ipValues[0])) &&
(IpCompare.IsLessOrEqual(ipAddress, ipValues[1])))
{
result = true;
break;
}
else
{
result = false;
}
}
else
{
throw new ArgumentException(string.Format("Invalid Access", this.Access));
}
}
return result;
}
#endregion
}
}
You can apply this Method that gets IP address: ASP.NET, C#