Last active
November 6, 2024 15:22
-
-
Save PeteGoo/21a5ab7636786670e47c to your computer and use it in GitHub Desktop.
Sending UDP datagrams in powershell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Send-UdpDatagram | |
{ | |
Param ([string] $EndPoint, | |
[int] $Port, | |
[string] $Message) | |
$IP = [System.Net.Dns]::GetHostAddresses($EndPoint) | |
$Address = [System.Net.IPAddress]::Parse($IP) | |
$EndPoints = New-Object System.Net.IPEndPoint($Address, $Port) | |
$Socket = New-Object System.Net.Sockets.UDPClient | |
$EncodedText = [Text.Encoding]::ASCII.GetBytes($Message) | |
$SendMessage = $Socket.Send($EncodedText, $EncodedText.Length, $EndPoints) | |
$Socket.Close() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Send-UdpDatagram -EndPoint "127.0.0.1" -Port 8125 -Message "test.mymetric:0|c" |
Danke!
Thank you!
Gracias
Obrigado
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks