Adds feature to set listen ip, defaults localhost

This commit is contained in:
Lord Hepipud 2021-08-04 10:04:15 +02:00
parent c8dacba9c5
commit cb31fe1f29
2 changed files with 13 additions and 4 deletions

View file

@ -20,6 +20,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
* [#301](https://github.com/Icinga/icinga-powershell-framework/pull/301) Improves error handling to no longer print passwords in case `String` is used for `SecureString` arguments * [#301](https://github.com/Icinga/icinga-powershell-framework/pull/301) Improves error handling to no longer print passwords in case `String` is used for `SecureString` arguments
* [#305](https://github.com/Icinga/icinga-powershell-framework/pull/305) Adds a new Cmdlet to test if functions with `Add-Type` are already present inside the current scope of the shell * [#305](https://github.com/Icinga/icinga-powershell-framework/pull/305) Adds a new Cmdlet to test if functions with `Add-Type` are already present inside the current scope of the shell
* [#306](https://github.com/Icinga/icinga-powershell-framework/pull/306) Adds new Cmdlet `Exit-IcingaThrowCritical` to throw critical exit with a custom message, either by force or by using string filtering and adds storing of plugin exit codes internally * [#306](https://github.com/Icinga/icinga-powershell-framework/pull/306) Adds new Cmdlet `Exit-IcingaThrowCritical` to throw critical exit with a custom message, either by force or by using string filtering and adds storing of plugin exit codes internally
* [#314](https://github.com/Icinga/icinga-powershell-framework/pull/314) Adds support to configure on which address TCP sockets are created on, defaults to `loopback` interface
## 1.5.2 (2021-07-09) ## 1.5.2 (2021-07-09)

View file

@ -1,6 +1,7 @@
function New-IcingaTCPSocket() function New-IcingaTCPSocket()
{ {
param( param (
[string]$Address = '',
[int]$Port = 0, [int]$Port = 0,
[switch]$Start = $FALSE [switch]$Start = $FALSE
); );
@ -9,7 +10,14 @@ function New-IcingaTCPSocket()
throw 'Please specify a valid port to open a TCP socket for'; throw 'Please specify a valid port to open a TCP socket for';
} }
$TCPSocket = [System.Net.Sockets.TcpListener]$Port; # Listen on localhost by default
$ListenAddress = New-Object System.Net.IPEndPoint([IPAddress]::Loopback, $Port);
if ([string]::IsNullOrEmpty($Address) -eq $FALSE) {
$ListenAddress = New-Object System.Net.IPEndPoint([IPAddress]::Parse($Address), $Port);
}
$TCPSocket = New-Object 'System.Net.Sockets.TcpListener' $ListenAddress;
Write-IcingaDebugMessage -Message ( Write-IcingaDebugMessage -Message (
[string]::Format( [string]::Format(