From 304508f6aa05b760b4127db61a73b116bfb53507 Mon Sep 17 00:00:00 2001 From: "marcusferl@weifer.de" Date: Thu, 18 Aug 2022 14:47:14 +0200 Subject: [PATCH] init --- .gitattributes | 63 ++++++ .gitignore | 363 +++++++++++++++++++++++++++++++++ IPConverter.sln | 25 +++ IPConverter/App.xaml | 9 + IPConverter/App.xaml.cs | 17 ++ IPConverter/AssemblyInfo.cs | 10 + IPConverter/Berechnung.cs | 158 ++++++++++++++ IPConverter/IPConverter.csproj | 10 + IPConverter/MainWindow.xaml | 52 +++++ IPConverter/MainWindow.xaml.cs | 60 ++++++ LICENSE.txt | 21 ++ README.md | 5 + 12 files changed, 793 insertions(+) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 IPConverter.sln create mode 100644 IPConverter/App.xaml create mode 100644 IPConverter/App.xaml.cs create mode 100644 IPConverter/AssemblyInfo.cs create mode 100644 IPConverter/Berechnung.cs create mode 100644 IPConverter/IPConverter.csproj create mode 100644 IPConverter/MainWindow.xaml create mode 100644 IPConverter/MainWindow.xaml.cs create mode 100644 LICENSE.txt create mode 100644 README.md diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1ff0c42 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9491a2f --- /dev/null +++ b/.gitignore @@ -0,0 +1,363 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Oo]ut/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd \ No newline at end of file diff --git a/IPConverter.sln b/IPConverter.sln new file mode 100644 index 0000000..ad956ed --- /dev/null +++ b/IPConverter.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.1.32421.90 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IPConverter", "IPConverter\IPConverter.csproj", "{EE1B9C3D-EBE0-4B0B-B878-B206A0B1F99E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {EE1B9C3D-EBE0-4B0B-B878-B206A0B1F99E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EE1B9C3D-EBE0-4B0B-B878-B206A0B1F99E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EE1B9C3D-EBE0-4B0B-B878-B206A0B1F99E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EE1B9C3D-EBE0-4B0B-B878-B206A0B1F99E}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {CC085BD8-3638-42C1-959B-F183FECAAC1A} + EndGlobalSection +EndGlobal diff --git a/IPConverter/App.xaml b/IPConverter/App.xaml new file mode 100644 index 0000000..551a7d3 --- /dev/null +++ b/IPConverter/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/IPConverter/App.xaml.cs b/IPConverter/App.xaml.cs new file mode 100644 index 0000000..4674bdd --- /dev/null +++ b/IPConverter/App.xaml.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace IPConverter +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/IPConverter/AssemblyInfo.cs b/IPConverter/AssemblyInfo.cs new file mode 100644 index 0000000..8b5504e --- /dev/null +++ b/IPConverter/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/IPConverter/Berechnung.cs b/IPConverter/Berechnung.cs new file mode 100644 index 0000000..303071f --- /dev/null +++ b/IPConverter/Berechnung.cs @@ -0,0 +1,158 @@ +using System; + + +namespace IPConverter +{ + internal class Berechnung + { + string _Ip; + string _BinärIp; + string _DecimalBroadcast; + string _BinärBroadcast; + string _DecimalMask; + string _BinärMask; + string _DecimalNetId; + string _BinärNetId; + string _DecimalMinIp; + string _BinärMinIp; + string _DecimalMaxIp; + string _BinärMaxIp; + int _Prefix; + public Berechnung(string ip, int prefix) + { + Ip = ip; + Prefix = prefix; + BinärIp = BinIPv4(ip); + BinärBroadcast = BinBroadcast(BinärIp, Prefix); + DecimalBroadcast = BinToDecimal(BinärBroadcast); + BinärMask = BinMask(Prefix); + DecimalMask = BinToDecimal(BinärMask); + BinärNetId = BinNet(BinärIp, Prefix); + DecimalNetId = BinToDecimal(BinärNetId); + BinärMaxIp = LastIp(BinärBroadcast); + DecimalMaxIp = BinToDecimal(BinärMaxIp); + BinärMinIp = FirstIp(BinärNetId); + DecimalMinIp = BinToDecimal(BinärMinIp); + + } + + + //Getter und Setter + public string Ip { get => _Ip; set => _Ip = value; } + public string BinärIp { get => _BinärIp; set => _BinärIp = value; } + public string DecimalBroadcast { get => _DecimalBroadcast; set => _DecimalBroadcast = value; } + public string BinärBroadcast { get => _BinärBroadcast; set => _BinärBroadcast = value; } + public string DecimalMask { get => _DecimalMask; set => _DecimalMask = value; } + public string BinärMask { get => _BinärMask; set => _BinärMask = value; } + public string DecimalNetId { get => _DecimalNetId; set => _DecimalNetId = value; } + public string BinärNetId { get => _BinärNetId; set => _BinärNetId = value; } + public string DecimalMinIp { get => _DecimalMinIp; set => _DecimalMinIp = value; } + public string BinärMinIp { get => _BinärMinIp; set => _BinärMinIp = value; } + public string DecimalMaxIp { get => _DecimalMaxIp; set => _DecimalMaxIp = value; } + public string BinärMaxIp { get => _BinärMaxIp; set => _BinärMaxIp = value; } + public int Prefix { get => _Prefix; set => _Prefix = value; } + + //Umwandlung der eingegebenen Ip in eine Binärip + string BinIPv4(string ip) + { + string[] ipArr = ip.Split('.'); + int[] intArr = new int[4]; + string[] binArr = new string[4]; + + for (int i = 0; i <= ipArr.Length - 1; i++) + { + intArr[i] = Convert.ToInt32(ipArr[i]); + } + for (int i = 0; i < intArr.Length; i++) + { + //Umwandlug in Binär + binArr[i] = Convert.ToString(intArr[i], 2); + } + for (int i = 0; i < binArr.Length; i++) + { + if (binArr[i].Length < 8) + { + string temp = new string('0', 8 - binArr[i].Length) + binArr[i]; // Füllt leere Stellen im Oktet auf + binArr[i] = temp; + } + } + return string.Join(" ", binArr); + } + + // Umwandlung von Binärer Ip und Prefix zu einer Binären Broadcast + string BinBroadcast(string binIp, int prefix) + { + string subBinIP = binIp.Replace(" ", ""); + string _subBinIp = new string('1', 32 - prefix); + subBinIP = subBinIP.Substring(0, prefix) + _subBinIp; + for (int i = 8; i <= subBinIP.Length; i += 8) + { + subBinIP = subBinIP.Insert(i, " "); //fügt alle 8 zeichen ein Leerzeichen hinzu + i++; + } + return subBinIP; + } + + //Allgemeine umwandlung von Binär zu Dezimal + string BinToDecimal(string bin) + { + var binArr = bin.Split(' '); + int[] _decimal = new int[4]; + for (int i = 0; i <= 3; i++) + { + _decimal[i] = Convert.ToInt32(binArr[i], 2); + } + return string.Join(' ', _decimal); + + } + + //SubnetMask in Binär anhand des Prefix + string BinMask(int prefix) + { + int maxPrefix = 32; + int mask = maxPrefix - prefix; + + // Prefix mal die 0 und der rest 11 im bereich von 32 + string prefixStr = new string('1', prefix) + new string('0', mask); ; + + for (int i = 8; i <= prefixStr.Length; i += 8) + { + prefixStr = prefixStr.Insert(i, " "); //fügt alle 8 zeichen ein Leerzeichen hinzu + i++; + } + return prefixStr; + } + string BinNet(string binIp, int prefix) + { + string subNetId = binIp.Replace(" ", ""); + string _subNetId = new string('0', 32 - prefix); + subNetId = subNetId.Substring(0, prefix) + _subNetId; + for (int i = 8; i <= subNetId.Length; i += 8) + { + subNetId = subNetId.Insert(i, " "); //fügt alle 8 zeichen ein Leerzeichen hinzu + i++; + } + return subNetId; + } + + // + string LastIp(string binBroadcast) + { + string lastIp = binBroadcast.Substring(0, binBroadcast.Length - 2) + "0"; + + return lastIp; + } + + // + string FirstIp(string binNetId) + { + string firstIp = binNetId.Substring(0, binNetId.Length - 2) + "1"; + + return firstIp; + } + + } + + + +} diff --git a/IPConverter/IPConverter.csproj b/IPConverter/IPConverter.csproj new file mode 100644 index 0000000..4106cb0 --- /dev/null +++ b/IPConverter/IPConverter.csproj @@ -0,0 +1,10 @@ + + + + WinExe + net6.0-windows + enable + true + + + diff --git a/IPConverter/MainWindow.xaml b/IPConverter/MainWindow.xaml new file mode 100644 index 0000000..57a8d3e --- /dev/null +++ b/IPConverter/MainWindow.xaml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/IPConverter/MainWindow.xaml.cs b/IPConverter/MainWindow.xaml.cs new file mode 100644 index 0000000..acd4a85 --- /dev/null +++ b/IPConverter/MainWindow.xaml.cs @@ -0,0 +1,60 @@ +using System.Windows; +using System.Windows.Controls; + + +namespace IPConverter +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public static int prefix; + public MainWindow() + { + InitializeComponent(); + FillComboBox(combo_box); + + } + public void FillComboBox(ComboBox combobox) + { + var end = 32; + for (prefix = 0; prefix <= end; prefix++) + { + combobox.Items.Add(prefix); + } + } + + private void Button_Click(object sender, RoutedEventArgs e) + { + if(combo_box.Text.Length > 0 && textbox_ip.Text.Length > 0) + { + int prefix = combo_box.SelectedIndex; + string ip = textbox_ip.Text; + Berechnung ipv4 = new Berechnung(ip, prefix); + + //Binäre Ausgaben + bin_broadcast.Text = ipv4.BinärBroadcast; + bin_mask.Text = ipv4.BinärMask; + bin_ipv4.Text = ipv4.BinärIp; + bin_net_id.Text = ipv4.BinärNetId; + bin_first_ip.Text = ipv4.BinärMinIp; + bin_lastip.Text = ipv4.BinärMaxIp; + + //Decimale Ausgaben + decimal_broadcast.Text = ipv4.DecimalBroadcast.Replace(' ', '.'); + decimal_mask.Text = ipv4.DecimalMask.Replace(' ', '.'); + decimal_net_id.Text = ipv4.DecimalNetId.Replace(' ', '.'); + decimal_ipv4.Text = textbox_ip.Text; + decimal_last_ip.Text = ipv4.DecimalMaxIp.Replace(' ', '.'); + decimal_fist_ip.Text = ipv4.DecimalMinIp.Replace(' ', '.'); + } + else + { + MessageBox.Show("Bitte Ipv4 und Prefix angeben"); + } + + + } + } +} diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..8aa2645 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) [year] [fullname] + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..3c04727 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# IPConverter + +Kleines Programm um Ipv4 zu Convertieren + +![Ip Converter](C:/Users/Mfproductions/Desktop/IpConverter.png) \ No newline at end of file