Skip to content

Commit 4bb17aa

Browse files
authored
Merge pull request #314 from Icinga:feature/listen_localhost_default_socket
Feature: Adds support to set listen ip, defaults to localhost We should ensure the local socket creation always defaults to the loopback interface, while making it configurable on which IP it listens.
2 parents c8dacba + cb31fe1 commit 4bb17aa

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

doc/31-Changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
2020
* [#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
2121
* [#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
2222
* [#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
23+
* [#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
2324

2425
## 1.5.2 (2021-07-09)
2526

lib/webserver/New-IcingaTCPSocket.psm1

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
function New-IcingaTCPSocket()
22
{
3-
param(
4-
[int]$Port = 0,
5-
[switch]$Start = $FALSE
3+
param (
4+
[string]$Address = '',
5+
[int]$Port = 0,
6+
[switch]$Start = $FALSE
67
);
78

89
if ($Port -eq 0) {
910
throw 'Please specify a valid port to open a TCP socket for';
1011
}
1112

12-
$TCPSocket = [System.Net.Sockets.TcpListener]$Port;
13+
# Listen on localhost by default
14+
$ListenAddress = New-Object System.Net.IPEndPoint([IPAddress]::Loopback, $Port);
15+
16+
if ([string]::IsNullOrEmpty($Address) -eq $FALSE) {
17+
$ListenAddress = New-Object System.Net.IPEndPoint([IPAddress]::Parse($Address), $Port);
18+
}
19+
20+
$TCPSocket = New-Object 'System.Net.Sockets.TcpListener' $ListenAddress;
1321

1422
Write-IcingaDebugMessage -Message (
1523
[string]::Format(

0 commit comments

Comments
 (0)