Improved code styling

This commit is contained in:
Christian Stein 2019-12-12 14:19:37 +01:00
parent 9adfe087d8
commit ce9257a30d
4 changed files with 27 additions and 15 deletions

View file

@ -24,11 +24,15 @@ function ConvertTo-IcingaIPv4BinaryString()
param(
[string]$IP
);
$IP = $IP -split '\.' | ForEach-Object {
[System.Convert]::ToString($_, 2).PadLeft(8, '0');
}
$IP = $IP -join '';
$IP = $IP -replace '\s','';
return @{'value' = $IP; 'name' = 'IPv4'}
return @{
'value' = $IP;
'name' = 'IPv4'
}
}

View file

@ -34,5 +34,8 @@ function ConvertTo-IcingaIPv6BinaryString()
$IP = $IP -join '';
$IP = $IP -replace '\s','';
return @{'value' = $IP; 'name' = 'IPv6'}
return @{
'value' = $IP;
'name' = 'IPv6'
}
}

View file

@ -28,14 +28,14 @@ function Expand-IcingaIPv6String()
[String]$IP
);
$Counter = 0
$RelV = -1
$Counter = 0;
$RelV = -1;
for ($Index = 0; $Index -lt $IP.Length; $Index++) {
if ($IP[$Index] -eq ':') {
$Counter++
$Counter++;
if (($Index - 1) -ge 0 -and $IP[$Index - 1] -eq ':'){
$RelV = $Index
$RelV = $Index;
}
}
}
@ -46,7 +46,7 @@ function Expand-IcingaIPv6String()
}
if ($Counter -lt 7) {
$IP = $IP.Substring(0, $RelV) + (':'*(7 - $Counter)) + $IP.Substring($RelV)
$IP = $IP.Substring(0, $RelV) + (':'*(7 - $Counter)) + $IP.Substring($RelV);
}
$Result = @();
@ -59,7 +59,7 @@ function Expand-IcingaIPv6String()
[System.Globalization.CultureInfo]::InvariantCulture,
[Ref]$Value
) | Out-Null;
$Result += ('{0:X4}' -f $Value)
$Result += ('{0:X4}' -f $Value);
}
$Result = $Result -join ':';

View file

@ -31,6 +31,11 @@ function Get-IcingaNetworkInterface()
[string]$IP
);
if ([string]::IsNullOrEmpty($IP)) {
Write-Host 'Please specify a valid IP-Address or FQDN';
return $null;
}
try {
$IP = ([System.Net.Dns]::GetHostAddresses($IP)).IPAddressToString;
} catch {