Projektdateien hinzufügen.
This commit is contained in:
25
Networking.sln
Normal file
25
Networking.sln
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio 15
|
||||||
|
VisualStudioVersion = 15.0.28307.1684
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Networking", "Networking\Networking.csproj", "{85D8795C-E9DC-4A59-B669-E2A8EEAC7A9E}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{85D8795C-E9DC-4A59-B669-E2A8EEAC7A9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{85D8795C-E9DC-4A59-B669-E2A8EEAC7A9E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{85D8795C-E9DC-4A59-B669-E2A8EEAC7A9E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{85D8795C-E9DC-4A59-B669-E2A8EEAC7A9E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {0C433798-2BCB-40EC-A25B-9013BBA832EE}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
382
Networking/IPTool.cs
Normal file
382
Networking/IPTool.cs
Normal file
@@ -0,0 +1,382 @@
|
|||||||
|
using System;
|
||||||
|
using System.Net;
|
||||||
|
|
||||||
|
namespace NetCalc
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Summary description for IPTool.
|
||||||
|
/// </summary>
|
||||||
|
public class IPTool
|
||||||
|
{
|
||||||
|
// first (0x00) only for fill - so array starts with bit 1
|
||||||
|
static byte[] bit = { 0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, (byte)0x80 };
|
||||||
|
|
||||||
|
protected string ip = null;
|
||||||
|
protected byte[] ipBytes = null;
|
||||||
|
//protected byte a,b,c,d;
|
||||||
|
protected int networkPrefix; // z.b. 24 for /24
|
||||||
|
protected bool firstSubNetBit = false;
|
||||||
|
|
||||||
|
public IPTool(string ip)
|
||||||
|
{
|
||||||
|
this.setIp(ip);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte getBit(int bit)
|
||||||
|
{
|
||||||
|
byte r = 0;
|
||||||
|
if (bit >= 1 && bit <= 8)
|
||||||
|
r = IPTool.bit[bit];
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte setBit(byte b, int bit)
|
||||||
|
{
|
||||||
|
if (bit >= 1 && bit <= 8)
|
||||||
|
return (byte)(b | IPTool.bit[bit]);
|
||||||
|
else return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool isBitSet(byte b, int bit)
|
||||||
|
{
|
||||||
|
bool r = false;
|
||||||
|
if (bit >= 1 && bit <= 8)
|
||||||
|
r = ((b & IPTool.bit[bit]) != 0);
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* return true if domainName is an IP
|
||||||
|
*/
|
||||||
|
static public bool isIP(String domainName)
|
||||||
|
{
|
||||||
|
//if (domainName.matches("[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}"))
|
||||||
|
if (domainName.Equals("[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}"))
|
||||||
|
return true;
|
||||||
|
else return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Converts (unsigned)byte to int
|
||||||
|
*/
|
||||||
|
public static int byte2int(byte b)
|
||||||
|
{
|
||||||
|
int i = b;
|
||||||
|
if (b < 0) i = b & 0x7f + 128;
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
// return first byte of IP
|
||||||
|
public byte get1Byte()
|
||||||
|
{
|
||||||
|
return this.ipBytes[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
// return second byte of IP
|
||||||
|
public byte get2Byte()
|
||||||
|
{
|
||||||
|
return this.ipBytes[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
// return third byte of IP
|
||||||
|
public byte get3Byte()
|
||||||
|
{
|
||||||
|
return this.ipBytes[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
// return fourth byte of IP
|
||||||
|
public byte get4Byte()
|
||||||
|
{
|
||||||
|
return this.ipBytes[3];
|
||||||
|
}
|
||||||
|
|
||||||
|
// return array with all bytes of IP
|
||||||
|
public byte[] getBytes()
|
||||||
|
{
|
||||||
|
//return InetAddress.getByName(this.ip).getAddress();
|
||||||
|
//return Dns.GetHostByName(this.ip).AddressList;
|
||||||
|
return IPAddress.Parse(this.ip).GetAddressBytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIp()
|
||||||
|
{
|
||||||
|
return this.ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIp(String ip)
|
||||||
|
{
|
||||||
|
this.ip = ip;
|
||||||
|
this.ipBytes = getBytes();
|
||||||
|
this.setPrefix2NetworkClassPrefix();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrefix2NetworkClassPrefix()
|
||||||
|
{
|
||||||
|
this.setNetworkPrefix(this.getNetworkClassPrefix());
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNetworkClassPrefix()
|
||||||
|
{
|
||||||
|
// set network-prefix with Class-Type
|
||||||
|
int netClass = getNetworkClass();
|
||||||
|
switch (netClass)
|
||||||
|
{
|
||||||
|
case 0: return 8; // Class A
|
||||||
|
case 1: return 16; // Class B
|
||||||
|
case 2: return 24; // Class C
|
||||||
|
//default: setNetworkPrefix(-1); // other Classes have no default Prefix
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* return -1 if out of range (0-255) or other error
|
||||||
|
*/
|
||||||
|
private int convertIPByte(String ipByte)
|
||||||
|
{
|
||||||
|
//int res = Integer.valueOf(ipByte).intValue();
|
||||||
|
int res = Int32.Parse(ipByte);
|
||||||
|
if (res < 0 || res > 255)
|
||||||
|
{
|
||||||
|
res = -1;
|
||||||
|
this.ip = null;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int getNetworkPrefix()
|
||||||
|
{
|
||||||
|
return this.networkPrefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param prefix
|
||||||
|
*/
|
||||||
|
public void setNetworkPrefix(int prefix)
|
||||||
|
{
|
||||||
|
this.networkPrefix = prefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNetworkClassName()
|
||||||
|
{
|
||||||
|
switch (this.getNetworkClass())
|
||||||
|
{
|
||||||
|
case 0: return "Class A";
|
||||||
|
case 1: return "Class B";
|
||||||
|
case 2: return "Class C";
|
||||||
|
case 3: return "Class D/Multicast";
|
||||||
|
case 4: return "Class E/not used";
|
||||||
|
default: return "error";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 0=Class A
|
||||||
|
* 1=Class B
|
||||||
|
* 2=Class C
|
||||||
|
* 3=Class D
|
||||||
|
* 4=Class E
|
||||||
|
* -1=error
|
||||||
|
*/
|
||||||
|
public int getNetworkClass()
|
||||||
|
{
|
||||||
|
// Test Class A: first bit=0
|
||||||
|
if (!IPTool.isBitSet(this.get1Byte(), 8)) return 0;
|
||||||
|
// Test Class B: first 2bit=10
|
||||||
|
else if (!IPTool.isBitSet(this.get1Byte(), 7)) return 1;
|
||||||
|
// Test Class C: first 3bit=110
|
||||||
|
else if (!IPTool.isBitSet(this.get1Byte(), 6)) return 2;
|
||||||
|
// Test Class D: first 4bit=1110
|
||||||
|
else if (!IPTool.isBitSet(this.get1Byte(), 5)) return 3;
|
||||||
|
// Test Class E: first 4bit=1111 ( = all other)
|
||||||
|
// else if (!IPTool.isBitSet(this.get1Byte(),8)) return 4;
|
||||||
|
else return 4;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Test Class A: first bit=0
|
||||||
|
if ((this.get1Byte() | (byte)0x7f) == (byte)0x7f) return 0;
|
||||||
|
// Test Class B: first 2bit=10
|
||||||
|
if ((this.get1Byte() | 0xbf) == 0xbf) return 1;
|
||||||
|
// Test Class C: first 3bit=110
|
||||||
|
if ((this.get1Byte() | 0xdf) == 0xdf) return 2;
|
||||||
|
// Test Class D: first 4bit=1110
|
||||||
|
if ((this.get1Byte() | 0xef) == 0xef) return 3;
|
||||||
|
// Test Class E: first 4bit=1111
|
||||||
|
if ((this.get1Byte() & 0xf0) == 0xf0) return 4;
|
||||||
|
return -1;
|
||||||
|
*/
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNetworkMask()
|
||||||
|
{
|
||||||
|
return getNetworkMaskByPrefix(this.networkPrefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNetworkMaskByPrefix(int prefix)
|
||||||
|
{
|
||||||
|
switch (prefix)
|
||||||
|
{
|
||||||
|
case 8: return "255.0.0.0";
|
||||||
|
case 9: return "255.128.0.0";
|
||||||
|
case 10: return "255.192.0.0";
|
||||||
|
case 11: return "255.224.0.0";
|
||||||
|
case 12: return "255.240.0.0";
|
||||||
|
case 13: return "255.248.0.0";
|
||||||
|
case 14: return "255.252.0.0";
|
||||||
|
case 15: return "255.254.0.0";
|
||||||
|
case 16: return "255.255.0.0";
|
||||||
|
case 17: return "255.255.128.0";
|
||||||
|
case 18: return "255.255.192.0";
|
||||||
|
case 19: return "255.255.224.0";
|
||||||
|
case 20: return "255.255.240.0";
|
||||||
|
case 21: return "255.255.248.0";
|
||||||
|
case 22: return "255.255.252.0";
|
||||||
|
case 23: return "255.255.254.0";
|
||||||
|
case 24: return "255.255.255.0";
|
||||||
|
case 25: return "255.255.255.128";
|
||||||
|
case 26: return "255.255.255.192";
|
||||||
|
case 27: return "255.255.255.224";
|
||||||
|
case 28: return "255.255.255.240";
|
||||||
|
case 29: return "255.255.255.248";
|
||||||
|
case 30: return "255.255.255.252";
|
||||||
|
default: return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMaxNetworkHosts()
|
||||||
|
{
|
||||||
|
// 2^(32-networkprefix)
|
||||||
|
// -2 ... because .0 and .255
|
||||||
|
return ((int)Math.Pow(2, (32 - this.networkPrefix))) - 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMaxSubNets()
|
||||||
|
{
|
||||||
|
// Bits from Subnet = prefix-class_prefix
|
||||||
|
|
||||||
|
int count = (int)Math.Pow(2, this.networkPrefix - this.getNetworkClassPrefix());
|
||||||
|
|
||||||
|
// -2 because 1 bit for routing
|
||||||
|
if (!this.isFirstSubNetBit() || this.getNetworkClassPrefix() == this.networkPrefix)
|
||||||
|
count -= 2;
|
||||||
|
|
||||||
|
if (count < 0) count = 0;
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getNetworkLong()
|
||||||
|
{
|
||||||
|
long mask = (long)Math.Pow(2, this.networkPrefix) - 1;
|
||||||
|
mask = mask << (32 - this.networkPrefix);
|
||||||
|
|
||||||
|
return (mask & ip2Long());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNetwork()
|
||||||
|
{
|
||||||
|
return long2String(getNetworkLong());
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getBroadCastLong()
|
||||||
|
{
|
||||||
|
long netMask = (long)Math.Pow(2, this.networkPrefix) - 1;
|
||||||
|
netMask = netMask << (32 - this.networkPrefix);
|
||||||
|
long hostMask = (long)Math.Pow(2, 32 - this.networkPrefix) - 1;
|
||||||
|
|
||||||
|
return (netMask = (ip2Long() & netMask) | hostMask);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBroadCast()
|
||||||
|
{
|
||||||
|
return long2String(getBroadCastLong());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String[] getNetworkIPRange()
|
||||||
|
{
|
||||||
|
String[] result = new String[2];
|
||||||
|
//String from, to;
|
||||||
|
/**
|
||||||
|
* Start
|
||||||
|
* +1 because first = network
|
||||||
|
*/
|
||||||
|
result[0] = long2String(getNetworkLong() + 1);
|
||||||
|
/**
|
||||||
|
* End
|
||||||
|
* -1 because last = broadcast
|
||||||
|
*/
|
||||||
|
result[1] = long2String(getBroadCastLong() - 1);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long ip2Long()
|
||||||
|
{
|
||||||
|
return ((long)(IPTool.byte2int(this.get1Byte()) * 256 +
|
||||||
|
IPTool.byte2int(this.get2Byte())) * 256 +
|
||||||
|
IPTool.byte2int(this.get3Byte())) * 256 +
|
||||||
|
IPTool.byte2int(this.get4Byte());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String long2String(long ip)
|
||||||
|
{
|
||||||
|
long a = (long)(ip & 0xff000000) >> 24;
|
||||||
|
long b = (long)(ip & 0x00ff0000) >> 16;
|
||||||
|
long c = (long)(ip & 0x0000ff00) >> 8;
|
||||||
|
long d = (long)(ip & 0xff);
|
||||||
|
|
||||||
|
return a + "." + b + "." + c + "." + d;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool isFirstSubNetBit()
|
||||||
|
{
|
||||||
|
return firstSubNetBit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFirstSubNetBit(bool b)
|
||||||
|
{
|
||||||
|
firstSubNetBit = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IPTool getNextIP(String ip)
|
||||||
|
{
|
||||||
|
IPTool nextIp = new IPTool(ip);
|
||||||
|
nextIp.setIp(nextIp.long2String(nextIp.ip2Long() + (long)1));
|
||||||
|
|
||||||
|
return nextIp;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public IPTool getNextSubNet(long numberOfHosts)
|
||||||
|
{
|
||||||
|
IPTool ip = IPTool.getNextIP(this.getBroadCast());
|
||||||
|
ip.setIp(this.long2String(ip.ip2Long() + (long)1));
|
||||||
|
ip.setFirstSubNetBit(this.isFirstSubNetBit());
|
||||||
|
|
||||||
|
int lastPrefix = ip.getNetworkClassPrefix();
|
||||||
|
|
||||||
|
int prefix = 30;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if (prefix < ip.getNetworkClassPrefix())
|
||||||
|
return null; // no subnet found
|
||||||
|
ip.setNetworkPrefix(prefix);
|
||||||
|
prefix--;
|
||||||
|
// ignore subnetbit?
|
||||||
|
if (!ip.isFirstSubNetBit() && prefix == lastPrefix + 1) prefix--;
|
||||||
|
|
||||||
|
}
|
||||||
|
while (ip.getMaxNetworkHosts() < numberOfHosts);
|
||||||
|
|
||||||
|
return ip;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
34
Networking/Networking.IPv4.xaml
Normal file
34
Networking/Networking.IPv4.xaml
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<UserControl x:Class="Networking.Networking_IPv4"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:local="clr-namespace:Networking"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
d:DesignHeight="450" d:DesignWidth="800" Background="White">
|
||||||
|
<Grid>
|
||||||
|
<ComboBox x:Name="tbNETClass" HorizontalAlignment="Left" Margin="328,61,0,0" VerticalAlignment="Top" Width="266" SelectionChanged="netClassComboBox_SelectedIndexChanged"/>
|
||||||
|
<TextBox x:Name="tbIPAddress" HorizontalAlignment="Left" Height="23" Margin="39,59,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="185" KeyDown="ipAddress_KeyDown" />
|
||||||
|
<ComboBox x:Name="prefixComboBox" HorizontalAlignment="Left" Margin="134,177,0,0" VerticalAlignment="Top" Width="99" Height="28" SelectionChanged="prefixComboBox_SelectedIndexChanged"/>
|
||||||
|
<ComboBox x:Name="netMaskComboBox" HorizontalAlignment="Left" Margin="328,177,0,0" VerticalAlignment="Top" Width="266" Height="28" SelectionChanged="netMaskComboBox_SelectedIndexChanged"/>
|
||||||
|
<CheckBox x:Name="firstBitCheckBox" Content="Allow 1st subnet-BIT" HorizontalAlignment="Left" Margin="654,177,0,0" VerticalAlignment="Top"/>
|
||||||
|
<TextBox x:Name="maxCountHosts" HorizontalAlignment="Left" Height="24" Margin="258,236,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="336"/>
|
||||||
|
<TextBox x:Name="calcNetwork" HorizontalAlignment="Left" Height="24" Margin="258,265,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="336"/>
|
||||||
|
<TextBox x:Name="calcBroadcast" HorizontalAlignment="Left" Height="24" Margin="258,294,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="336"/>
|
||||||
|
<TextBox x:Name="calcIPRange" HorizontalAlignment="Left" Height="24" Margin="258,323,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="336"/>
|
||||||
|
<TextBox x:Name="clacMaxNetCount" HorizontalAlignment="Left" Height="24" Margin="258,352,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="336"/>
|
||||||
|
<TextBox x:Name="nextNumOfHosts" HorizontalAlignment="Left" Height="24" Margin="258,381,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="70"/>
|
||||||
|
<Label x:Name="noticeLabel" Content="Label" HorizontalAlignment="Left" Margin="134,96,0,0" VerticalAlignment="Top" Height="54" Width="460"/>
|
||||||
|
<Label Content="Maximum number of Hosts:" HorizontalContentAlignment="Right" HorizontalAlignment="Left" Margin="10,236,0,0" VerticalAlignment="Top" Width="228" Height="24"/>
|
||||||
|
<Label Content="Network:" HorizontalAlignment="Left" HorizontalContentAlignment="Right" Margin="10,265,0,0" VerticalAlignment="Top" Width="228" Height="24"/>
|
||||||
|
<Label Content="Broadcast:" HorizontalAlignment="Left" HorizontalContentAlignment="Right" Margin="10,294,0,0" VerticalAlignment="Top" Width="228" Height="24"/>
|
||||||
|
<Label Content="IP - range:" HorizontalAlignment="Left" HorizontalContentAlignment="Right" Margin="10,323,0,0" VerticalAlignment="Top" Width="228" Height="24"/>
|
||||||
|
<Label Content="Maximum number of subnets:" HorizontalAlignment="Left" HorizontalContentAlignment="Right" Margin="10,352,0,0" VerticalAlignment="Top" Width="228" Height="24"/>
|
||||||
|
<Label Content="Wanted number of hosts:" HorizontalAlignment="Left" HorizontalContentAlignment="Right" Margin="10,381,0,0" VerticalAlignment="Top" Width="228" Height="24"/>
|
||||||
|
<Label Content="Prefix:" HorizontalAlignment="Left" HorizontalContentAlignment="Right" Margin="28,177,0,0" VerticalAlignment="Top" Height="28" Width="101"/>
|
||||||
|
<Label Content="Netmask:" HorizontalAlignment="Left" HorizontalContentAlignment="Right" Margin="243,177,0,0" VerticalAlignment="Top" Height="28" Width="80"/>
|
||||||
|
<Label Content="IP:" HorizontalAlignment="Left" HorizontalContentAlignment="Right" Margin="10,55,0,0" VerticalAlignment="Top" Height="28" Width="24"/>
|
||||||
|
<Label Content="Network-Type:" HorizontalAlignment="Left" HorizontalContentAlignment="Right" Margin="238,58,0,0" VerticalAlignment="Top" Width="90" Height="24"/>
|
||||||
|
<Button Content="Show next subnet with this number of hosts" x:Name="btnNextSubnet" HorizontalAlignment="Left" Margin="333,383,0,0" VerticalAlignment="Top" Width="261" Click="btnNextSubnet_Click"/>
|
||||||
|
</Grid>
|
||||||
|
</UserControl>
|
||||||
350
Networking/Networking.IPv4.xaml.cs
Normal file
350
Networking/Networking.IPv4.xaml.cs
Normal file
@@ -0,0 +1,350 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Data;
|
||||||
|
using System.Windows.Documents;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
using System.Windows.Navigation;
|
||||||
|
using System.Windows.Shapes;
|
||||||
|
using NetCalc;
|
||||||
|
using PTConverter.Plugin;
|
||||||
|
|
||||||
|
namespace Networking
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Interaktionslogik für Networking.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class Networking_IPv4 : UserControl, IPlugin, IPage
|
||||||
|
{
|
||||||
|
#region Declarations
|
||||||
|
protected IPTool ip = null;
|
||||||
|
protected bool fill = false; // lock events wenn updating
|
||||||
|
protected bool isIP = false;
|
||||||
|
|
||||||
|
public string Author => "Kevin Krüger";
|
||||||
|
|
||||||
|
public string Company => "PeaceToke";
|
||||||
|
|
||||||
|
public string PluginName => "Networking";
|
||||||
|
|
||||||
|
public string Description => "Calculate networks very easy!";
|
||||||
|
|
||||||
|
public string Version => "1.0.0";
|
||||||
|
|
||||||
|
public string IconLink => "https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fwww.clipartmax.com%2Fpng%2Fmiddle%2F276-2769230_networking-deep-neural-network-icon.png&f=1&nofb=1";
|
||||||
|
|
||||||
|
public IPage Page => this;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
public Networking_IPv4()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
|
||||||
|
|
||||||
|
tbNETClass.ItemsSource = new object[] {
|
||||||
|
"Class A: 0.0.0.0-127.255.255.255",
|
||||||
|
"Class B: 128.0.0.0-191.255.255.255",
|
||||||
|
"Class C: 192.0.0.0-223.255.255.255",
|
||||||
|
"Class D: 224.0.0.0-239.255.255.255",
|
||||||
|
"Class E: 240.0.0.0-254.255.255.255"};
|
||||||
|
|
||||||
|
tbNETClass.SelectedIndex = 0;
|
||||||
|
}
|
||||||
|
public string GetCategory() => "Networking";
|
||||||
|
public string GetUnderCategory() => "IPv4";
|
||||||
|
public UserControl GetPage() => new Networking_IPv4();
|
||||||
|
|
||||||
|
#region Methods Used
|
||||||
|
protected void newIP()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ip = new IPTool(tbIPAddress.Text);
|
||||||
|
fillIPCalc();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
MessageBox.Show(e.StackTrace);
|
||||||
|
}
|
||||||
|
//catch (UnknownHostException e)
|
||||||
|
//{
|
||||||
|
// main.getJp_Calc().getJtf_IP_Calc().setBackground(java.awt.Color.red);
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void fillIPCalc()
|
||||||
|
{
|
||||||
|
if (ip == null || ip.getIp() == null) return;
|
||||||
|
this.fill = true;
|
||||||
|
|
||||||
|
this.fillComboBox_Prefix();
|
||||||
|
this.fillComboBox_NetworkMask();
|
||||||
|
|
||||||
|
// Prefix
|
||||||
|
int prefix = ip.getNetworkPrefix();
|
||||||
|
if (prefix >= 8 && prefix <= 30)
|
||||||
|
{
|
||||||
|
if (prefix != ip.getNetworkClassPrefix() && !ip.isFirstSubNetBit()) prefix--;
|
||||||
|
prefix = prefix - ip.getNetworkClassPrefix();
|
||||||
|
}
|
||||||
|
else prefix = -1;
|
||||||
|
prefixComboBox.SelectedIndex = prefix;
|
||||||
|
// NetMask
|
||||||
|
netMaskComboBox.SelectedIndex = prefix;
|
||||||
|
|
||||||
|
// folgendes nur wenn Netzwerkmaske vorhanden
|
||||||
|
// nicht der Fall bei Class-D oder E
|
||||||
|
if (prefix != -1)
|
||||||
|
{
|
||||||
|
// max Net Hosts
|
||||||
|
maxCountHosts.Text = ip.getMaxNetworkHosts() + "";
|
||||||
|
// Net Class
|
||||||
|
calcNetwork.Text = ip.getNetworkClassName();
|
||||||
|
// Broadcast
|
||||||
|
calcBroadcast.Text = ip.getBroadCast();
|
||||||
|
// Network
|
||||||
|
calcNetwork.Text = ip.getNetwork();
|
||||||
|
// Net-Class
|
||||||
|
tbNETClass.SelectedIndex = ip.getNetworkClass();
|
||||||
|
// IP-Range
|
||||||
|
string[] ipRange = ip.getNetworkIPRange();
|
||||||
|
calcIPRange.Text = ipRange[0] + " - " + ipRange[1];
|
||||||
|
// max Sub-Nets
|
||||||
|
clacMaxNetCount.Text = ip.getMaxSubNets() + "";
|
||||||
|
}
|
||||||
|
else // Anzeige löschen
|
||||||
|
{
|
||||||
|
// max Net Hosts
|
||||||
|
maxCountHosts.Text = "";
|
||||||
|
// Net Class
|
||||||
|
calcNetwork.Text = "";
|
||||||
|
// Broadcast
|
||||||
|
calcBroadcast.Text = "";
|
||||||
|
// Network
|
||||||
|
calcNetwork.Text = "";
|
||||||
|
// IP-Range
|
||||||
|
calcIPRange.Text = "";
|
||||||
|
// max Sub-Nets
|
||||||
|
clacMaxNetCount.Text = "";
|
||||||
|
}
|
||||||
|
// Description
|
||||||
|
string desc = "";
|
||||||
|
if (ip.get1Byte() >= (byte)64 && ip.getNetworkClass() == (byte)0) // 64.
|
||||||
|
desc = "reserved for future use";
|
||||||
|
if (ip.get1Byte() == (byte)127) // localhost
|
||||||
|
desc = "localhost and loopback-Device - your one computer";
|
||||||
|
if (ip.get1Byte() == (byte)10) // private 10.0.0.0
|
||||||
|
desc = "private net - for internal use only, would not be routed in internet";
|
||||||
|
if (ip.get1Byte() == (byte)192 && ip.get2Byte() == (byte)168) // private 192. - 168.
|
||||||
|
desc = "private net - for internal use only, would not be routed in internet";
|
||||||
|
if (ip.get1Byte() == (byte)172 && (ip.get2Byte() >= (byte)16 && ip.get2Byte() <= (byte)31)) //private 172.16 - 172.31
|
||||||
|
desc = "private net - for internal use only, would not be routed in internet";
|
||||||
|
if ((ip.get1Byte() == (byte)169) && (ip.get2Byte() == (byte)254)) // 169.254.
|
||||||
|
desc = "APIPA Automatic Private IP Addressing";
|
||||||
|
if (ip.get1Byte() == (byte)0) // 0.
|
||||||
|
desc = "0.0.0.0 = default route";
|
||||||
|
if (ip.getNetworkClass() == (byte)4) // Class-E
|
||||||
|
desc = "reserved for future use";
|
||||||
|
if (ip.getNetworkClass() == (byte)3) // Class-D
|
||||||
|
desc = "used for multicast";
|
||||||
|
|
||||||
|
noticeLabel.Content = "Info stuff: " + desc;
|
||||||
|
this.fill = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void fillComboBox_Prefix()
|
||||||
|
{
|
||||||
|
if (ip == null || ip.getIp() == null) return;
|
||||||
|
|
||||||
|
prefixComboBox.Items.Clear();
|
||||||
|
|
||||||
|
if (ip.getNetworkClassPrefix() == -1)
|
||||||
|
{
|
||||||
|
prefixComboBox.Items.Add("");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int startPrefix = ip.getNetworkClassPrefix();
|
||||||
|
// first is Networkclass
|
||||||
|
prefixComboBox.Items.Add(startPrefix + "");
|
||||||
|
startPrefix++;
|
||||||
|
if (!ip.isFirstSubNetBit()) startPrefix++;
|
||||||
|
|
||||||
|
for (int i = startPrefix; i <= 30; i++)
|
||||||
|
prefixComboBox.Items.Add(i + "");
|
||||||
|
}
|
||||||
|
protected void fillComboBox_NetworkMask()
|
||||||
|
{
|
||||||
|
if (ip == null || ip.getIp() == null) return;
|
||||||
|
|
||||||
|
netMaskComboBox.Items.Clear();
|
||||||
|
|
||||||
|
if (ip.getNetworkClassPrefix() == -1)
|
||||||
|
{
|
||||||
|
netMaskComboBox.Items.Add("");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int startPrefix = ip.getNetworkClassPrefix();
|
||||||
|
// first is Networkclass
|
||||||
|
netMaskComboBox.Items.Add(ip.getNetworkMaskByPrefix(startPrefix));
|
||||||
|
startPrefix++;
|
||||||
|
if (!ip.isFirstSubNetBit()) startPrefix++;
|
||||||
|
|
||||||
|
for (int i = startPrefix; i <= 30; i++)
|
||||||
|
netMaskComboBox.Items.Add(ip.getNetworkMaskByPrefix(i));
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Events
|
||||||
|
private void ipAddress_Leave(object sender, System.EventArgs e)
|
||||||
|
{
|
||||||
|
newIP();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ipAddress_KeyDown(object sender, KeyEventArgs e)
|
||||||
|
{
|
||||||
|
if (e.Key == Key.Enter)
|
||||||
|
{
|
||||||
|
newIP();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void prefixComboBox_SelectedIndexChanged(object sender, System.EventArgs e)
|
||||||
|
{
|
||||||
|
if (ip == null || ip.getIp() == null || fill) return;
|
||||||
|
if (ip.getNetworkClassPrefix() == -1) return;
|
||||||
|
|
||||||
|
int prefix = Int32.Parse((string)prefixComboBox.SelectedItem);
|
||||||
|
ip.setNetworkPrefix(prefix);
|
||||||
|
|
||||||
|
fillIPCalc();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void netMaskComboBox_SelectedIndexChanged(object sender, System.EventArgs e)
|
||||||
|
{
|
||||||
|
if (ip == null || ip.getIp() == null || fill) return;
|
||||||
|
if (ip.getNetworkClassPrefix() == -1) return;
|
||||||
|
|
||||||
|
int select = netMaskComboBox.SelectedIndex;
|
||||||
|
int prefix = select + ip.getNetworkClassPrefix();
|
||||||
|
if (select != 0 && !ip.isFirstSubNetBit()) prefix++;
|
||||||
|
//int prefix = Integer.parseInt((String)main.getJcb_Calc_NetworkMask().getSelectedItem());
|
||||||
|
ip.setNetworkPrefix(prefix);
|
||||||
|
|
||||||
|
fillIPCalc();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void netClassComboBox_SelectedIndexChanged(object sender, System.EventArgs e)
|
||||||
|
{
|
||||||
|
if (fill) return;
|
||||||
|
switch (tbNETClass.SelectedIndex)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
tbIPAddress.Text = "1.0.0.1";
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
tbIPAddress.Text = "128.0.0.1";
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
tbIPAddress.Text = "192.0.0.1";
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
tbIPAddress.Text = "224.0.0.1";
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
tbIPAddress.Text = "240.0.0.1";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
newIP();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void firstBitCheckBox_CheckedChanged(object sender, System.EventArgs e)
|
||||||
|
{
|
||||||
|
if (ip == null || ip.getIp() == null || fill) return;
|
||||||
|
|
||||||
|
ip.setFirstSubNetBit((bool)firstBitCheckBox.IsChecked);
|
||||||
|
fillIPCalc();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void nextSubnetButt_Click(object sender, System.EventArgs e)
|
||||||
|
{
|
||||||
|
if (ip == null || ip.getIp() == null || fill) return;
|
||||||
|
///nextNumOfHosts.BackColor = Color.White;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int hosts = Int32.Parse(nextNumOfHosts.Text);
|
||||||
|
|
||||||
|
IPTool newIp = ip.getNextSubNet(hosts);
|
||||||
|
if (newIp == null)
|
||||||
|
{
|
||||||
|
//ToManyHosts
|
||||||
|
noticeLabel.Content = "Info stuff: Number of hosts in this network-class not possible!";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ip = newIp;
|
||||||
|
tbIPAddress.Text = ip.getIp();
|
||||||
|
}
|
||||||
|
catch (System.FormatException)
|
||||||
|
{
|
||||||
|
//nextNumOfHosts.BackColor = Color.Red;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
catch (Exception e1)
|
||||||
|
{
|
||||||
|
MessageBox.Show(e1.StackTrace);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fillIPCalc();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void calcButt_Click(object sender, System.EventArgs e)
|
||||||
|
{
|
||||||
|
newIP();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private void btnNextSubnet_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (ip == null || ip.getIp() == null || fill) return;
|
||||||
|
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int hosts = Int32.Parse(nextNumOfHosts.Text);
|
||||||
|
|
||||||
|
IPTool newIp = ip.getNextSubNet(hosts);
|
||||||
|
if (newIp == null)
|
||||||
|
{
|
||||||
|
//ToManyHosts
|
||||||
|
noticeLabel.Content = "Info stuff: Number of hosts in this network-class not possible!";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ip = newIp;
|
||||||
|
tbIPAddress.Text = ip.getIp();
|
||||||
|
}
|
||||||
|
catch (System.FormatException)
|
||||||
|
{
|
||||||
|
//nextNumOfHosts.BackColor = Color.Red;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
catch (Exception e1)
|
||||||
|
{
|
||||||
|
MessageBox.Show(e1.StackTrace);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fillIPCalc();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
64
Networking/Networking.csproj
Normal file
64
Networking/Networking.csproj
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProjectGuid>{85D8795C-E9DC-4A59-B669-E2A8EEAC7A9E}</ProjectGuid>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
|
<RootNamespace>Networking</RootNamespace>
|
||||||
|
<AssemblyName>Networking</AssemblyName>
|
||||||
|
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||||
|
<FileAlignment>512</FileAlignment>
|
||||||
|
<Deterministic>true</Deterministic>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="PresentationCore" />
|
||||||
|
<Reference Include="PresentationFramework" />
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Core" />
|
||||||
|
<Reference Include="System.Xaml" />
|
||||||
|
<Reference Include="System.Xml.Linq" />
|
||||||
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
|
<Reference Include="Microsoft.CSharp" />
|
||||||
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Net.Http" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
|
<Reference Include="WindowsBase" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="IPTool.cs" />
|
||||||
|
<Compile Include="Networking.IPv4.xaml.cs">
|
||||||
|
<DependentUpon>Networking.IPv4.xaml</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Page Include="Networking.IPv4.xaml">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
</Page>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<WCFMetadata Include="Connected Services\" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
</Project>
|
||||||
36
Networking/Properties/AssemblyInfo.cs
Normal file
36
Networking/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
// Allgemeine Informationen über eine Assembly werden über die folgenden
|
||||||
|
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
|
||||||
|
// die einer Assembly zugeordnet sind.
|
||||||
|
[assembly: AssemblyTitle("Networking")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("")]
|
||||||
|
[assembly: AssemblyProduct("Networking")]
|
||||||
|
[assembly: AssemblyCopyright("Copyright © 2021")]
|
||||||
|
[assembly: AssemblyTrademark("")]
|
||||||
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
|
||||||
|
// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von
|
||||||
|
// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen.
|
||||||
|
[assembly: ComVisible(false)]
|
||||||
|
|
||||||
|
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
|
||||||
|
[assembly: Guid("85d8795c-e9dc-4a59-b669-e2a8eeac7a9e")]
|
||||||
|
|
||||||
|
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
|
||||||
|
//
|
||||||
|
// Hauptversion
|
||||||
|
// Nebenversion
|
||||||
|
// Buildnummer
|
||||||
|
// Revision
|
||||||
|
//
|
||||||
|
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
|
||||||
|
// indem Sie "*" wie unten gezeigt eingeben:
|
||||||
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
|
[assembly: AssemblyVersion("1.0.0.0")]
|
||||||
|
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||||
Reference in New Issue
Block a user