This commit is contained in:
marcusferl 2022-08-31 21:34:53 +02:00
parent 49569a33d5
commit b879581158
5 changed files with 53 additions and 22 deletions

View File

@ -11,6 +11,8 @@ import { MatFormFieldModule } from '@angular/material/form-field';
import { MatSelectModule } from '@angular/material/select'; import { MatSelectModule } from '@angular/material/select';
import { OutputComponent } from './output/output.component'; import { OutputComponent } from './output/output.component';
import { FormsModule } from '@angular/forms'; import { FormsModule } from '@angular/forms';
import { MatIconModule } from '@angular/material/icon';
import { MatButtonModule } from '@angular/material/button';
@NgModule({ @NgModule({
@ -27,7 +29,9 @@ import { FormsModule } from '@angular/forms';
MatInputModule, MatInputModule,
MatFormFieldModule, MatFormFieldModule,
MatSelectModule, MatSelectModule,
FormsModule FormsModule,
MatIconModule,
MatButtonModule
], ],
providers: [], providers: [],
bootstrap: [AppComponent] bootstrap: [AppComponent]

View File

@ -20,7 +20,6 @@ export class Berechnung {
binToDec(bin: string) { binToDec(bin: string) {
var arr = bin.split(" ") var arr = bin.split(" ")
alert(arr)
let binNum = "" let binNum = ""
for (let index = 0; index < arr.length - 1; index++) { for (let index = 0; index < arr.length - 1; index++) {
binNum += parseInt(arr[index], 2).toString() + "."; binNum += parseInt(arr[index], 2).toString() + ".";
@ -30,9 +29,9 @@ export class Berechnung {
} }
subNetMask(prefix: number) { binSubNetMask(prefix: number) {
let mask = "" let binMask = "1".repeat(prefix) + "0".repeat((32 - prefix))
return mask; return this.splitBinNumberString(binMask)
} }
broadCastBin(binIp: string, prefix: number) { broadCastBin(binIp: string, prefix: number) {
@ -40,24 +39,31 @@ export class Berechnung {
let prefixIp = arr.join(""); let prefixIp = arr.join("");
let hostbin = prefixIp.slice(0, prefix); let hostbin = prefixIp.slice(0, prefix);
hostbin = hostbin + "1".repeat(32 - prefix); hostbin = hostbin + "1".repeat(32 - prefix);
for (let i = 8; i <= hostbin.length; i += 8) { return this.splitBinNumberString(hostbin)
hostbin = [hostbin.slice(0, i), " ", hostbin.slice(i)].join('') }
netIdBin(binIp: string, prefix: number) {
var arr = binIp.split(' ');
let prefixIp = arr.join("");
let hostbin = prefixIp.slice(0, prefix);
hostbin = hostbin + "0".repeat(32 - prefix);
return this.splitBinNumberString(hostbin)
}
minIp(binNetID: string) {
return binNetID.slice(0, binNetID.length - 2) + "1 "
}
maxIp(binBroadcast: string) {
return binBroadcast.slice(0, binBroadcast.length - 2) + "0 "
}
splitBinNumberString(binString: string) {
for (let i = 8; i <= binString.length; i += 8) {
binString = [binString.slice(0, i), " ", binString.slice(i)].join('')
i++ i++
} }
return hostbin return binString;
}
netId(mask: string) {
let netId;
return netId;
}
minIp() {
return null;
}
max() {
return null;
} }
} }

View File

@ -12,5 +12,8 @@
</mat-option> </mat-option>
</mat-select> </mat-select>
</mat-form-field> </mat-form-field>
<button mat-raised-button (click)="onClick()">Calculate</button>
<button mat-fab aria-label="Calculate">
<mat-icon class="icon">swap_horiz</mat-icon>
</button>
</div> </div>

View File

@ -1,8 +1,13 @@
.input_field { .input_field {
min-width: 150px; min-width: 150px;
max-width: 500px; max-width: 500px;
height: 58px;
width: 100%; width: 100%;
margin-top: 15px;
margin-right: 12px; margin-right: 12px;
margin-left: 5px;
border: 1px solid rgba(0, 0, 0, 0.30);
border-radius: 10px;
} }
@ -10,5 +15,10 @@
min-width: 50px; min-width: 50px;
max-width: 100px; max-width: 100px;
width: 100%; width: 100%;
margin-top: 15px;
margin-right: 12px; margin-right: 12px;
} }
.button {
padding-top: 10px;
}

View File

@ -24,6 +24,14 @@ export class InputComponent implements OnInit {
this.service.bin_dec_dict.Ipv4.dec = 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.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) this.service.bin_dec_dict.Broadcast.dec = calc.binToDec(this.service.bin_dec_dict.Broadcast.bin)
this.service.bin_dec_dict.Subnet.bin = calc.binSubNetMask(this.prefix_selection)
this.service.bin_dec_dict.Subnet.dec = calc.binToDec(this.service.bin_dec_dict.Subnet.bin)
this.service.bin_dec_dict.NetID.bin = calc.netIdBin(this.service.bin_dec_dict.Ipv4.bin, this.prefix_selection)
this.service.bin_dec_dict.NetID.dec = calc.binToDec(this.service.bin_dec_dict.NetID.bin)
this.service.bin_dec_dict.FirstIP.bin = calc.minIp(this.service.bin_dec_dict.NetID.bin)
this.service.bin_dec_dict.FirstIP.dec = calc.binToDec(this.service.bin_dec_dict.FirstIP.bin)
this.service.bin_dec_dict.LastIP.bin = calc.maxIp(this.service.bin_dec_dict.Broadcast.bin)
this.service.bin_dec_dict.LastIP.dec = calc.binToDec(this.service.bin_dec_dict.LastIP.bin)
} }
ngOnInit(): void { ngOnInit(): void {