mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
Improved code styling
This commit is contained in:
parent
9adfe087d8
commit
ce9257a30d
4 changed files with 27 additions and 15 deletions
|
|
@ -24,11 +24,15 @@ function ConvertTo-IcingaIPv4BinaryString()
|
||||||
param(
|
param(
|
||||||
[string]$IP
|
[string]$IP
|
||||||
);
|
);
|
||||||
|
|
||||||
$IP = $IP -split '\.' | ForEach-Object {
|
$IP = $IP -split '\.' | ForEach-Object {
|
||||||
[System.Convert]::ToString($_,2).PadLeft(8,'0');
|
[System.Convert]::ToString($_, 2).PadLeft(8, '0');
|
||||||
}
|
}
|
||||||
$IP = $IP -join '';
|
$IP = $IP -join '';
|
||||||
$IP = $IP -replace '\s','';
|
$IP = $IP -replace '\s','';
|
||||||
|
|
||||||
return @{'value' = $IP; 'name' = 'IPv4'}
|
return @{
|
||||||
}
|
'value' = $IP;
|
||||||
|
'name' = 'IPv4'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ function ConvertTo-IcingaIPv6BinaryString()
|
||||||
param(
|
param(
|
||||||
[string]$IP
|
[string]$IP
|
||||||
);
|
);
|
||||||
[string]$IP = Expand-IcingaIPv6String $IP;
|
[string]$IP = Expand-IcingaIPv6String $IP;
|
||||||
[array]$IPArr = $IP.Split(':');
|
[array]$IPArr = $IP.Split(':');
|
||||||
|
|
||||||
$IPArr = $IPArr.ToCharArray();
|
$IPArr = $IPArr.ToCharArray();
|
||||||
|
|
@ -34,5 +34,8 @@ function ConvertTo-IcingaIPv6BinaryString()
|
||||||
$IP = $IP -join '';
|
$IP = $IP -join '';
|
||||||
$IP = $IP -replace '\s','';
|
$IP = $IP -replace '\s','';
|
||||||
|
|
||||||
return @{'value' = $IP; 'name' = 'IPv6'}
|
return @{
|
||||||
}
|
'value' = $IP;
|
||||||
|
'name' = 'IPv6'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,14 +28,14 @@ function Expand-IcingaIPv6String()
|
||||||
[String]$IP
|
[String]$IP
|
||||||
);
|
);
|
||||||
|
|
||||||
$Counter = 0
|
$Counter = 0;
|
||||||
$RelV = -1
|
$RelV = -1;
|
||||||
|
|
||||||
for($Index = 0; $Index -lt $IP.Length; $Index++) {
|
for ($Index = 0; $Index -lt $IP.Length; $Index++) {
|
||||||
if ($IP[$Index] -eq ':') {
|
if ($IP[$Index] -eq ':') {
|
||||||
$Counter++
|
$Counter++;
|
||||||
if (($Index - 1) -ge 0 -and $IP[$Index - 1] -eq ':'){
|
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) {
|
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 = @();
|
$Result = @();
|
||||||
|
|
@ -59,9 +59,9 @@ function Expand-IcingaIPv6String()
|
||||||
[System.Globalization.CultureInfo]::InvariantCulture,
|
[System.Globalization.CultureInfo]::InvariantCulture,
|
||||||
[Ref]$Value
|
[Ref]$Value
|
||||||
) | Out-Null;
|
) | Out-Null;
|
||||||
$Result += ('{0:X4}' -f $Value)
|
$Result += ('{0:X4}' -f $Value);
|
||||||
}
|
}
|
||||||
$Result = $Result -join ':';
|
$Result = $Result -join ':';
|
||||||
|
|
||||||
return $Result;
|
return $Result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,11 @@ function Get-IcingaNetworkInterface()
|
||||||
[string]$IP
|
[string]$IP
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ([string]::IsNullOrEmpty($IP)) {
|
||||||
|
Write-Host 'Please specify a valid IP-Address or FQDN';
|
||||||
|
return $null;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$IP = ([System.Net.Dns]::GetHostAddresses($IP)).IPAddressToString;
|
$IP = ([System.Net.Dns]::GetHostAddresses($IP)).IPAddressToString;
|
||||||
} catch {
|
} catch {
|
||||||
|
|
@ -116,4 +121,4 @@ function Get-IcingaNetworkInterface()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ((Get-NetIPAddress -InterfaceIndex (Get-NetRoute | Where-Object -Property DestinationPrefix -like '0.0.0.0/0')[0].IfIndex -AddressFamily $IPBinStringMaster.name).IPAddress).split('%')[0];
|
return ((Get-NetIPAddress -InterfaceIndex (Get-NetRoute | Where-Object -Property DestinationPrefix -like '0.0.0.0/0')[0].IfIndex -AddressFamily $IPBinStringMaster.name).IPAddress).split('%')[0];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue