我们撰写了一份内容,使一名管理人能够阻挡/限制排位。
这是否容易与否?
我正在考虑研究每一数字[范围]。
标准ip v4的工作是否涉及?
我们撰写了一份内容,使一名管理人能够阻挡/限制排位。
这是否容易与否?
我正在考虑研究每一数字[范围]。
标准ip v4的工作是否涉及?
I d 将其转换为ger,然后比较 in。 但正确之处取决于你如何界定范围。
UInt32 Ip4ToInt(string ip)
{
UInt32[] parts=ip.Split( . ).Select(s=>UInt32.Parse(s)).ToArray();
if (parts.Length != 4)
throw new ArgumentException("InvalidIP");
return (parts[0]<<24) | (parts[1]<<16) | (parts[2]<<8) | parts[3];
}
例如,1.1.1.99
是<代码>1.1-1.1.2.2的一部分? 在比较每个组别时,比较分类时是t。
public static bool CheckIfIpValid(string allowedStartIp, string allowedEndIp, string ip)
{
// if both start and end ip s are null, every user with these credential can log in, no ip restriction needed.
if (string.IsNullOrEmpty(allowedStartIp) && string.IsNullOrEmpty(allowedEndIp))
return true;
bool isStartNull = string.IsNullOrEmpty(allowedStartIp),
isEndNull = string.IsNullOrEmpty(allowedEndIp);
string[] startIpBlocks, endIpBlocks, userIp = ip.Split( . );
if (!string.IsNullOrEmpty(allowedStartIp))
startIpBlocks = allowedStartIp.Split( . );
else
startIpBlocks = "0.0.0.0".Split( . );
if (!string.IsNullOrEmpty(allowedEndIp))
endIpBlocks = allowedEndIp.Split( . );
else
endIpBlocks = "999.999.999.999".Split( . );
for (int i = 0; i < userIp.Length; i++)
{
// if current block is smaller than allowed minimum, ip is not valid.
if (Convert.ToInt32(userIp[i]) < Convert.ToInt32(startIpBlocks[i]))
return false;
// if current block is greater than allowed maximum, ip is not valid.
else if (Convert.ToInt32(userIp[i]) > Convert.ToInt32(endIpBlocks[i]))
return false;
// if current block is greater than allowed minimum, ip is valid.
else if ((Convert.ToInt32(userIp[i]) > Convert.ToInt32(startIpBlocks[i])) && !isStartNull)
return true;
}
return true;
}
I know that System.Net.IPAddress.Address
is deprecated
But I think that this is the easiest way:
bool result = false;
System.Net.IPAddress iStart = System.Net.IPAddress.Parse(ipStart);
System.Net.IPAddress iEnd = System.Net.IPAddress.Parse(ipEnd);
System.Net.IPAddress iIp = System.Net.IPAddress.Parse(ip);
if (iStart.Address <= iIp.Address && iEnd.Address >= iIp.Address)
{
result = true;
}
页: 1 例如:127.0.0.1
最近,我需要在伙伴关系中做类似的事情。 NET Core。 我采用了<代码>System.Net.IPAddress的做法,将IP地址作为byte
阵列。 然后,我比较各阵列中的内容,看IP的主题地址是否属于范围。 这是《InChaos和Pabuc法典》提出的类似解决办法。
System.Net.IPAddress.TryParse(ipAddressRule.StartIpAddress, out var startIpAddress);
System.Net.IPAddress.TryParse(ipAddressRule.EndIpAddress, out var endIpAddress);
if (IsWithinAllowedIpAddresses(clientIpAddress.GetAddressBytes(), startIpAddress.GetAddressBytes(), endIpAddress.GetAddressBytes()))
{
...
}
public bool IsWithinAllowedIpAddresses(byte[] ipAddress, byte[] startAllowIpAddress, byte[] endAllowIpAddress)
{
if (ipAddress.Length != startAllowIpAddress.Length)
{
throw new ArgumentException();
}
if (ipAddress.Length != endAllowIpAddress.Length)
{
throw new ArgumentException();
}
for (int i = 0; i < ipAddress.Length; i++)
{
if (ipAddress[i] < startAllowIpAddress[I])
{
return false;
}
if (ipAddress[i] > endAllowIpAddress[I])
{
return false;
}
}
return true;
}
In my webpages I have references to js and images as such: "../../Content/Images/"Filename" In my code if I reference a file as above, it doesnt work so i have to write: "c:/miscfiles/"filename" 1-...
I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...
Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...
I m looking for best practices here. Sorry. I know it s subjective, but there are a lot of smart people here, so there ought to be some "very good" ways of doing this. I have a custom object called ...
I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...
i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...
For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?
I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!