Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Kalyan IP range check
//Title of this code //Rextester.Program.Main is the entry point for your code. Don't change it. using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { //Your code goes here //var x = Environment.CurrentDirectory; Console.WriteLine(IsIpInRange("67.63.175.193", "67.63.175.254", "67.63.175.205", 2)); } /// <summary> /// /// </summary> /// <param name="lowRange"></param> /// <param name="highRange"></param> /// <param name="mode">default is 2, 1 = exclude lower end but include upper end, 2= include both upper and lower end, 3 = exclude both low and high boundaries, 4= include lower but exclude upper end</param> /// <returns></returns> public static bool IsIpInRange(string lowRange, string highRange, string _ipAddress, int mode = 2) { var lowerRange = Ip2Long(lowRange); var upperRange = Ip2Long(highRange); var ipAddress =Ip2Long(_ipAddress); switch (mode) { case 1: return ipAddress > lowerRange && ipAddress <= upperRange; case 3: return ipAddress > lowerRange && ipAddress < upperRange; case 4: return ipAddress >= lowerRange && ipAddress < upperRange; case 2: default: return ipAddress >= lowerRange && ipAddress <= upperRange; } } public static long Ip2Long(string ip) { string[] ipBytes; double num = 0; if (!string.IsNullOrEmpty(ip)) { ipBytes = ip.Split('.'); for (int i = ipBytes.Length - 1; i >= 0; i--) { num += ((int.Parse(ipBytes[i]) % 256) * Math.Pow(256, (3 - i))); } } return (long)num; } } }
run
|
edit
|
history
|
help
0
asxs xscsss
an attempt at making a usable code thing (failed lol)
ElaineBrown
database exterior 0.1
Testing 006
dfgthyjui8u7yt5rewsx
Watch Jurassic World Dominion Online Free
Frase
String to Decimal CSHARP
Expand Treeview Job Entry