mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-04-21 17:38:19 +02:00
Updated the script
This commit is contained in:
parent
23fde0f67b
commit
f548434d31
@ -6,31 +6,27 @@
|
|||||||
# Source: github.com/fleschutz/PowerShell
|
# Source: github.com/fleschutz/PowerShell
|
||||||
# License: CC0
|
# License: CC0
|
||||||
|
|
||||||
param([string]$IP, [int]$Port, [string]$Message)
|
param([string]$TargetIP, [int]$TargetPort, [string]$Message)
|
||||||
|
|
||||||
if ($IP -eq "" ) {
|
if ($TargetIP -eq "" ) {
|
||||||
$IP = read-host "Enter target IP address"
|
$TargetIP = read-host "Enter target IP address"
|
||||||
}
|
}
|
||||||
if ($Port -eq 0 ) {
|
if ($TargetPort -eq 0 ) {
|
||||||
$Port = read-host "Enter target port"
|
$TargetPort = read-host "Enter target port"
|
||||||
}
|
}
|
||||||
if ($Message -eq "" ) {
|
if ($Message -eq "" ) {
|
||||||
$Message = read-host "Enter message to send"
|
$Message = read-host "Enter message to send"
|
||||||
}
|
}
|
||||||
|
|
||||||
function Send-UdpDatagram
|
try {
|
||||||
{
|
$IP = [System.Net.Dns]::GetHostAddresses($TargetIP)
|
||||||
param([string]$EndPoint, [int]$Port, [string]$Message)
|
|
||||||
|
|
||||||
$IP = [System.Net.Dns]::GetHostAddresses($EndPoint)
|
|
||||||
$Address = [System.Net.IPAddress]::Parse($IP)
|
$Address = [System.Net.IPAddress]::Parse($IP)
|
||||||
$EndPoints = New-Object System.Net.IPEndPoint($Address, $Port)
|
$EndPoints = New-Object System.Net.IPEndPoint($Address, $TargetPort)
|
||||||
$Socket = New-Object System.Net.Sockets.UDPClient
|
$Socket = New-Object System.Net.Sockets.UDPClient
|
||||||
$EncodedText = [Text.Encoding]::ASCII.GetBytes($Message)
|
$EncodedText = [Text.Encoding]::ASCII.GetBytes($Message)
|
||||||
$SendMessage = $Socket.Send($EncodedText, $EncodedText.Length, $EndPoints)
|
$SendMessage = $Socket.Send($EncodedText, $EncodedText.Length, $EndPoints)
|
||||||
$Socket.Close()
|
$Socket.Close()
|
||||||
}
|
echo "Done."
|
||||||
|
exit 0
|
||||||
Send-UdpDatagram $IP $Port $Message
|
} catch { Write-Error $Error[0] }
|
||||||
echo "Done."
|
exit 1
|
||||||
exit 0
|
|
||||||
|
Loading…
Reference in New Issue
Block a user