mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-02-02 10:59:14 +01:00
Added send-udp.ps1
This commit is contained in:
parent
4ea6819c7f
commit
d3720b7745
@ -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
36
Scripts/send-udp.ps1
Executable 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
|
Loading…
Reference in New Issue
Block a user