Skip to content

Instantly share code, notes, and snippets.

@PeteGoo
Last active December 29, 2023 00:07
Show Gist options
  • Star 44 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • 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

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