diff --git a/src/app/backend/berechnung.ts b/src/app/backend/berechnung.ts index c09bd88..ed3667a 100644 --- a/src/app/backend/berechnung.ts +++ b/src/app/backend/berechnung.ts @@ -18,13 +18,33 @@ export class Berechnung { return this.binArr.join(".") } + binToDec(bin: string) { + var arr = bin.split(" ") + alert(arr) + let binNum = "" + for (let index = 0; index < arr.length; index++) { + binNum += parseInt(arr[index], 2).toString(); + + } + return binNum; + + } + subNetMask(prefix: number) { let mask = "" return mask; } - broadCast(arr: any[]) { - + broadCastBin(binIp: string, prefix: number) { + var arr = binIp.split('.'); + let prefixIp = arr.join(""); + let hostbin = prefixIp.slice(0, prefix); + hostbin = hostbin + "1".repeat(32 - prefix); + for (let i = 8; i <= hostbin.length; i += 8) { + hostbin = [hostbin.slice(0, i), " ", hostbin.slice(i)].join('') + i++ + } + return hostbin } netId(mask: string) { diff --git a/src/app/input/input.component.html b/src/app/input/input.component.html index d3ca544..e10eef7 100644 --- a/src/app/input/input.component.html +++ b/src/app/input/input.component.html @@ -12,5 +12,5 @@ - + \ No newline at end of file diff --git a/src/app/input/input.component.ts b/src/app/input/input.component.ts index 1d2fc4d..dffc278 100644 --- a/src/app/input/input.component.ts +++ b/src/app/input/input.component.ts @@ -1,5 +1,6 @@ import { Component, OnInit } from '@angular/core'; import { Berechnung } from '../backend/berechnung'; +import { MyserviceService } from '../myservice.service'; @Component({ selector: 'app-input', @@ -11,18 +12,18 @@ export class InputComponent implements OnInit { ipv4_eingabe: string = ""; prefix_selection: number = 0; - - constructor() { + constructor(public service: MyserviceService) { for (let i = 0; i <= 32; i++) { this.counter.push(i); } } onClick() { - var berechnung = new Berechnung; - let number = berechnung.decToBin(this.ipv4_eingabe) - alert(number) - + var calc = new Berechnung; + this.service.bin_dec_dict.Ipv4.bin = calc.decToBin(this.ipv4_eingabe) + this.service.bin_dec_dict.Ipv4.dec = this.ipv4_eingabe; + this.service.bin_dec_dict.Broadcast.bin = calc.broadCastBin(this.service.bin_dec_dict.Ipv4.bin, this.prefix_selection); + this.service.bin_dec_dict.Broadcast.dec = calc.binToDec(this.service.bin_dec_dict.Broadcast.bin) } ngOnInit(): void { diff --git a/src/app/myservice.service.ts b/src/app/myservice.service.ts index 3376bf4..6c8cb07 100644 --- a/src/app/myservice.service.ts +++ b/src/app/myservice.service.ts @@ -4,6 +4,31 @@ import { Injectable } from '@angular/core'; providedIn: 'root' }) export class MyserviceService { - + bin_dec_dict = { + Ipv4: { + dec: "", + bin: "" + }, + Subnet: { + dec: "", + bin: "" + }, + Broadcast: { + dec: "", + bin: "" + }, + NetID: { + dec: "", + bin: "" + }, + FirstIP: { + dec: "", + bin: "" + }, + LastIP: { + dec: "", + bin: "" + } + } constructor() { } } diff --git a/src/app/output/output.component.html b/src/app/output/output.component.html index 6aa43a3..6db2ac2 100644 --- a/src/app/output/output.component.html +++ b/src/app/output/output.component.html @@ -1,7 +1,42 @@ -
- +
+
-

-

+

+

+
+
+
+ +
+

+

+
+
+
+ +
+

+

+
+
+
+ +
+

+

+
+
+
+ +
+

+

+
+
+
+ +
+

+

\ No newline at end of file diff --git a/src/app/output/output.component.ts b/src/app/output/output.component.ts index f5a01d1..227437a 100644 --- a/src/app/output/output.component.ts +++ b/src/app/output/output.component.ts @@ -1,6 +1,6 @@ import { Component, OnInit } from '@angular/core'; -import { Berechnung } from '../backend/berechnung'; -import { InputComponent } from '../input/input.component'; +import { MyserviceService } from '../myservice.service'; + @Component({ @@ -10,40 +10,14 @@ import { InputComponent } from '../input/input.component'; }) export class OutputComponent implements OnInit { - - // Dictionary - bin_dec_dict = { - ipv4_dec: "", - ipv4_bin: "", - subnet_dec: "", - subnet_bin: "", - broadcast_dec: "", - broadcast_bin: "", - netID_de: "", - netID_bin: "", - firstIP_dec: "", - firstIP_bin: "", - lastIP_dec: "", - lastIP_bin: "" - } - - - - bin = ""; - dec = ""; + inputIp = ""; prefix = 0; outArr = ["IPv4", "Subnetmask:", "Broadcast:", "Net-ID:", "First Ip:", "Last Ip:"] - constructor() { + constructor(public service: MyserviceService) { } - onClick() { - var br = new Berechnung; - // Dict Zugriff - this.bin_dec_dict.ipv4_bin = br.decToBin(this.dec) - this.bin_dec_dict.subnet_bin = br.subNetMask(this.prefix) - } ngOnInit(): void {