Advertisement
Guest User

ipcalc

a guest
Feb 25th, 2020
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.15 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace HeiseCalculator
  8. {
  9.     class Program
  10.     {
  11.         static bool[] ip_1 = new bool[32];
  12.         static bool[] ip_2 = new bool[32];
  13.  
  14.         static void Main(string[] args)
  15.         {
  16.             //Console.WriteLine("Enter ip1");
  17.             //string a = Console.ReadLine();
  18.             //Console.WriteLine("Enter ip2");
  19.             //string b = Console.ReadLine();
  20.             //Console.WriteLine("Are these IPs correct?\n{0}\n{1}\ny/n", a, b);
  21.             //Console.WriteLine("Press enter to continue...");
  22.             string ip = "193.99.144.85";
  23.             string ip2 = "213.61.187.98";
  24.             Console.WriteLine(ip);
  25.             ip_1 = ConvertToIP(ip);
  26.             ip_2 = ConvertToIP(ip2);
  27.             int cidr = CalculateCIDR(ip_1, ip_2);
  28.             Console.ReadKey();
  29.         }
  30.  
  31.         static bool[] ConvertToIP(string ip)
  32.         {
  33.             bool[] arr_b = new bool[32];
  34.             string[] arr = ip.Split('.');
  35.             for (int i = 0; i < arr.Length; i++)
  36.             {
  37.                 arr[i] = Convert.ToString(Convert.ToInt32(arr[i], 10),2).PadLeft(8, '0');
  38.             }
  39.             int a = 0;
  40.             ip = string.Concat(arr[0], arr[1], arr[2], arr[3]);
  41.             Console.WriteLine(ip);
  42.             for (int i = 0; i < ip.Length; i++)
  43.             {
  44.                 if (ip[i] == '1')
  45.                 {
  46.                     arr_b[i] = true;
  47.                 }
  48.                 if (ip[i] == '0')
  49.                 {
  50.                     arr_b[i] = false;
  51.                 }
  52.             }
  53.             return arr_b;
  54.         }
  55.  
  56.         static int CalculateCIDR(bool[] ip_1, bool[] ip_2)
  57.         {
  58.             int a = 0;
  59.             while (ip_1[a] == ip_2[a])
  60.             {
  61.                 a++;
  62.             }
  63.             return a;
  64.         }
  65.  
  66.         static int CalculateIP(bool[] ip, int cidr)
  67.         {
  68.         }
  69.  
  70.  
  71.         static void CVtoBinary(string dec)
  72.         {
  73.  
  74.         }
  75.  
  76.         static string ConvertToDecimal(bool[] ip)
  77.         {
  78.             return null;
  79.         }
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement