Skip to content

Instantly share code, notes, and snippets.

@PeteGoo
Last active November 6, 2024 15:22
Show Gist options
  • Save PeteGoo/21a5ab7636786670e47c to your computer and use it in GitHub Desktop.
Save PeteGoo/21a5ab7636786670e47c to your computer and use it in GitHub Desktop.
Sending UDP datagrams in powershell
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()
}
Send-UdpDatagram -EndPoint "127.0.0.1" -Port 8125 -Message "test.mymetric:0|c"
@Asimatasert
Copy link

Thanks

@Pragmataraxia
Copy link

Danke!

@ozeray
Copy link

ozeray commented Apr 14, 2023

Thank you!

@bjsmiley
Copy link

bjsmiley commented Jul 5, 2023

Gracias

@ares1977
Copy link

Obrigado

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment