Created
October 6, 2021 15:15
-
-
Save Forevka/5c5961ee411dd58ee17e252a9ab3c330 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Define port and target IP address | |
# Random here! | |
[int] $Port = 48157 | |
[string] $host = "hellish-body.auto.playit.gg" | |
$Address =[System.Net.Dns]::GetHostAddresses($host); #[system.net.IPAddress]::Parse($IP) | |
# Create IP Endpoint | |
# $End = New-Object System.Net.IPEndPoint $Address, $port | |
# Create Socket | |
$Saddrf = [System.Net.Sockets.AddressFamily]::InterNetwork | |
$Stype = [System.Net.Sockets.SocketType]::Dgram | |
$Ptype = [System.Net.Sockets.ProtocolType]::UDP | |
$Sock = New-Object System.Net.Sockets.Socket $saddrf, $stype, $ptype | |
$Sock.TTL = 26 | |
# Connect to socket | |
$sock.Connect($Address, $Port) | |
# Create encoded buffer | |
$Enc = [System.Text.Encoding]::ASCII | |
$Message = "Jerry Garcia Rocks`n"*10 | |
$Buffer = $Enc.GetBytes($Message) | |
# Send the buffer | |
$Sent = $Sock.Send($Buffer) | |
"{0} characters sent to: {1} " -f $Sent,$IP | |
"Message is:" | |
$Message | |
# End of Script |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param( $address="Any", $port=2020 ) | |
try{ | |
$endpoint = new-object System.Net.IPEndPoint( [IPAddress]::$address, $port ) | |
$udpclient = new-object System.Net.Sockets.UdpClient $port | |
} | |
catch{ | |
throw $_ | |
exit -1 | |
} | |
Write-Host "Press ESC to stop the udp server ..." -fore yellow | |
Write-Host "" | |
while( $true ) | |
{ | |
if( $host.ui.RawUi.KeyAvailable ) | |
{ | |
$key = $host.ui.RawUI.ReadKey( "NoEcho,IncludeKeyUp,IncludeKeyDown" ) | |
if( $key.VirtualKeyCode -eq 27 ) | |
{ break } | |
} | |
if( $udpclient.Available ) | |
{ | |
$content = $udpclient.Receive( [ref]$endpoint ) | |
Write-Host "$($endpoint.Address.IPAddressToString):$($endpoint.Port) $([Text.Encoding]::ASCII.GetString($content))" | |
} | |
} | |
$udpclient.Close( ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment