-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
70 lines (60 loc) · 2.37 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Net;
using static System.Console;
using static IPKalkulator.OutputFormatters;
using static IPKalkulator.Parsers;
namespace IPKalkulator
{
static class Program
{
//Oblikujemo izhod programa
static void WriteMainOutput(IPAddress ipAddress, IPAddress subnetMask)
{
WriteLine("Input interpreted as:");
WriteStandardFormat("Address: ", ipAddress);
WriteNetmask(subnetMask);
WriteStandardFormat("Wildcard: ", SubnetMask.GetWildCard(subnetMask));
WriteLine();
WriteLine("=>");
WriteLine();
WriteNetwork(ipAddress, subnetMask);
WriteStandardFormat("Broadcast: ", ipAddress.GetBroadcastAddress(subnetMask));
IPAddress hostMin = ipAddress.GetNetworkAddress(subnetMask).Increment(),
hostMax = ipAddress.GetBroadcastAddress(subnetMask).Decrement();
WriteStandardFormat("HostMin: ", hostMin);
WriteStandardFormat("HostMax: ", hostMax);
WriteAvailableHosts(subnetMask, ipAddress);
}
static void Main()
{
Title = "IP Calculator by Franci Šacer";
WindowWidth = BufferWidth = 90;
IPAddress ipAddress, subnetMask;
WriteLine("Enter valid IPv4 address with or without CIDR extension:");
string input = ReadLine();
if (input == null)
{
goto finish;
}
//Ločimo dele vhoda
string[] addressParts = input.Split(new[] { ' ', '/'}, StringSplitOptions.RemoveEmptyEntries);
//Preverimo, katero obliko bi naj vnesel uporabnik.
switch (addressParts.Length)
{
case 1:
if (!ParseWithIPv4Subnet(addressParts[0], out ipAddress, out subnetMask)) goto finish;
break;
case 2:
if (!ParseWithCIDR(addressParts, out ipAddress, out subnetMask)) goto finish;
break;
default:
WriteLine("Invalid number of spaces or slashes.");
goto finish;
}
WriteLine();
WriteMainOutput(ipAddress, subnetMask);
finish:
ReadLine();
}
}
}