@@ -16,3 +16,168 @@ One-liner to convert all PNG Images of a folder to JPG images:
16
16
``` ps1
17
17
Get-ChildItem -Path (Get-Location) -Filter *.png | ForEach-Object { $img=[System.Drawing.Image]::FromFile($_.FullName); $jpg=([System.IO.Path]::ChangeExtension($_.FullName, '.jpg')); $enc=[System.Drawing.Imaging.ImageCodecInfo]::GetImageEncoders()|?{$_.MimeType -eq 'image/jpeg'}; $par=New-Object System.Drawing.Imaging.EncoderParameters(1); $par.Param[0]=New-Object System.Drawing.Imaging.EncoderParameter([System.Drawing.Imaging.Encoder]::Quality,90); $img.Save($jpg,$enc,$par); $img.Dispose() }; Write-Output 'Conversion complete.'
18
18
```
19
+
20
+ ## Netzwerk
21
+
22
+ ### UDP
23
+
24
+ #### UDP Sender
25
+
26
+ ``` ps1
27
+ $udpSender = New-Object System.Net.Sockets.UdpClient
28
+ $bytes = [System.Text.Encoding]::UTF8.GetBytes("Hallo vom Client")
29
+ $udpSender.Send($bytes, $bytes.Length, "1.2.3.5", 12345)
30
+ $udpSender.Close()
31
+ ```
32
+
33
+ #### UDP Listener
34
+
35
+ ``` ps1
36
+ $udpClient = New-Object System.Net.Sockets.UdpClient 12345
37
+ $remoteEP = New-Object System.Net.IPEndPoint ([System.Net.IPAddress]::Any, 0)
38
+
39
+ Write-Host "Lausche auf UDP-Port 12345..."
40
+
41
+ while ($true) {
42
+ $data = $udpClient.Receive([ref]$remoteEP)
43
+ $text = [System.Text.Encoding]::UTF8.GetString($data)
44
+ Write-Host "Empfangen von $($remoteEP.Address): $text"
45
+ }
46
+ ```
47
+
48
+ #### UDP Check
49
+
50
+ ``` ps1
51
+ Get-NetUDPEndpoint | Select-Object -Property LocalAddress, LocalPort, OwningProcess | Sort-Object LocalPort
52
+ ```
53
+
54
+ ### With iPerf
55
+
56
+ UDP Download
57
+
58
+ ``` ps1
59
+ iperf3.exe -c <server> -u -P 10 -4 -R
60
+ ```
61
+
62
+ UDP Upload
63
+
64
+ ``` ps1
65
+ iperf3.exe -c <server> -u -P 10 -4
66
+ ```
67
+
68
+ ### TCP
69
+
70
+ #### TCP Connect
71
+
72
+ ``` ps1
73
+ try { (New-Object Net.Sockets.TcpClient).Connect("1.2.3.4", 7600); "offen" } catch { "zu" }
74
+ ```
75
+
76
+ #### TCP Firewall check
77
+
78
+ ``` ps1
79
+ $tcp = New-Object System.Net.Sockets.TcpClient
80
+ $tcp.ReceiveTimeout = 3000
81
+ $tcp.SendTimeout = 3000
82
+ $sw = [System.Diagnostics.Stopwatch]::StartNew()
83
+ try {
84
+ $tcp.Connect("1.2.3.4", 7600)
85
+ "Port offen"
86
+ } catch {
87
+ $sw.Stop()
88
+ if ($sw.ElapsedMilliseconds -ge 2500) {
89
+ "Möglicherweise gefiltert (Timeout)"
90
+ } else {
91
+ "Port wahrscheinlich geschlossen (RST empfangen)"
92
+ }
93
+ }
94
+ ```
95
+
96
+ #### TCP Listener
97
+
98
+ ``` ps1
99
+ $listener = [System.Net.Sockets.TcpListener]::Create(7600)
100
+ $listener.Start()
101
+ Write-Host "TCP-Listener läuft auf Port 7600..."
102
+
103
+ while ($true) {
104
+ if ($listener.Pending()) {
105
+ $client = $listener.AcceptTcpClient()
106
+ Write-Host "Neue Verbindung: $($client.Client.RemoteEndPoint)"
107
+ $client.Close()
108
+ }
109
+ Start-Sleep -Milliseconds 500
110
+ }
111
+ ```
112
+
113
+ #### TCP Check
114
+
115
+ ``` ps1
116
+ Get-NetTCPConnection -State Listen | Select-Object -Property LocalAddress, LocalPort, OwningProcess | Sort-Object LocalPort
117
+ ```
118
+
119
+ #### TCP Check with iPerf
120
+
121
+ TCP Download
122
+
123
+ ``` ps1
124
+ iperf3.exe -c <server> -P 10 -4 -R
125
+ ```
126
+
127
+ TCP Upload
128
+
129
+ ``` ps1
130
+ iperf3.exe -c <server> -P 10 -4
131
+ ```
132
+
133
+ ### Multicast
134
+
135
+ Checks
136
+
137
+ - Port must be allowed (check Firewall local or in network)
138
+ - Verify that the network infrastructure (switches, routers) allows multicast (no filtering/IGMP blocking).
139
+ - Ensure both sender and receiver are on the same LAN/subnet (unless you have multicast routing set up).
140
+ - Use a multicast address in the range 224.0.0.0 to 239.255.255.255
141
+
142
+ #### Listener
143
+
144
+ ``` ps1
145
+ $groupAddress = "239.255.0.1"
146
+ $port = 5001
147
+
148
+ $udpClient = New-Object System.Net.Sockets.UdpClient
149
+ $localEp = New-Object System.Net.IPEndPoint ([System.Net.IPAddress]::Any, $port)
150
+ $udpClient.Client.SetSocketOption([System.Net.Sockets.SocketOptionLevel]::Socket, [System.Net.Sockets.SocketOptionName]::ReuseAddress, $true)
151
+ $udpClient.ExclusiveAddressUse = $false
152
+ $udpClient.Client.Bind($localEp)
153
+
154
+ $udpClient.JoinMulticastGroup([System.Net.IPAddress]::Parse($groupAddress))
155
+
156
+ Write-Host "Listening for multicast on $groupAddress:$port..."
157
+ while ($true) {
158
+ $received = $udpClient.Receive([ref]$localEp)
159
+ $text = [System.Text.Encoding]::UTF8.GetString($received)
160
+ Write-Host "Received from $($localEp.Address): $text"
161
+ }
162
+ ```
163
+
164
+ ### Sender
165
+
166
+ ``` ps1
167
+ $groupAddress = "239.255.0.1"
168
+ $port = 5001
169
+ $message = "Hello multicast from $(hostname)"
170
+ $remoteIp = [System.Net.IPAddress]::Parse($groupAddress)
171
+ $remoteEp = New-Object System.Net.IPEndPoint $remoteIp, $port
172
+
173
+ $udpClient = New-Object System.Net.Sockets.UdpClient
174
+ $bytes = [System.Text.Encoding]::UTF8.GetBytes($message)
175
+
176
+ for ($i = 1; $i -le 10; $i++) {
177
+ $udpClient.Send($bytes, $bytes.Length, $remoteEp) | Out-Null
178
+ Write-Host "Sent: $message"
179
+ Start-Sleep -Seconds 1
180
+ }
181
+
182
+ $udpClient.Close()
183
+ ```
0 commit comments