Added send-udp.ps1

This commit is contained in:
Markus Fleschutz 2020-11-28 08:18:36 +00:00
parent 4ea6819c7f
commit d3720b7745
2 changed files with 38 additions and 1 deletions

View File

@ -25,7 +25,8 @@ The following PowerShell scripts can be found in the `Scripts/` subfolder:
* [poweroff.ps1](Scripts/poweroff.ps1) - halts the local computer, administrator rights might be needed
* [news.ps1](Scripts/news.ps1) - prints the latest news
* [reboot.ps1](Scripts/reboot.ps1) - reboots the local computer, administrator rights might be needed
* [send-email.ps1](Scripts/send-email.ps1) - sends an email
* [send-email.ps1](Scripts/send-email.ps1) - sends an email message
* [send-udp.ps1](Scripts/send-udp.ps1) - sends a UDP datagram message to the given IP address and port
* [SHA1.ps1](Scripts/SHA1.ps1) - prints the SHA1 checksum of the given file
* [SHA256.ps1](Scripts/SHA256.ps1) - prints the SHA256 checksum of the given file
* [speak.ps1](Scripts/speak.ps1) - speaks the given text by text-to-speech (TTS)

36
Scripts/send-udp.ps1 Executable file
View File

@ -0,0 +1,36 @@
#!/snap/bin/powershell
# Syntax: ./send-udp.ps1 [<IP>] [<port>] [<message>]
# Description: sends a UDP datagram message to the given IP address and port
# Author: Markus Fleschutz
# Source: github.com/fleschutz/PowerShell
# License: CC0
param([string]$IP, [int]$Port, [string]$Message)
if ($IP -eq "" ) {
$IP = read-host "Enter target IP address"
}
if ($Port -eq 0 ) {
$Port = read-host "Enter target port"
}
if ($Message -eq "" ) {
$Message = read-host "Enter message to send"
}
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 $IP $Port $Message
echo "Done."
exit 0