Servidor
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
##Server $port=2021 $endpoint = new-object System.Net.IPEndPoint ([IPAddress]::Any,$port) $udpclient=new-Object System.Net.Sockets.UdpClient $port $content=$udpclient.Receive([ref]$endpoint) $convert=[Text.Encoding]::ASCII.GetString($content) $spli=$convert.Split("*") $user=$spli[0] $pass=$spli[1] if($user -eq "user" -and $pass -eq "pass") { Write-Host "Login correcto desde el cliente" #Comprobar que el hash recibido y el hash del fichero recbido es correcto $content=$udpclient.Receive([ref]$endpoint) $convert=[Text.Encoding]::ASCII.GetString($content) $convert | Out-File ficherorecibido.txt $content=$udpclient.Receive([ref]$endpoint) $convert=[Text.Encoding]::ASCII.GetString($content) if($convert -eq (Get-FileHash ficherorecibido.txt).hash) { "Iguales hash" } else { "No iguales hash" } } else { Write-Host "No login" } $udpclient.Close() |

Cliente
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
##Client $port=2021 $endpoint = new-object System.Net.IPEndPoint ([IPAddress]::Loopback,$port) $udpclient=new-Object System.Net.Sockets.UdpClient $val="user*pass" $b=[Text.Encoding]::ASCII.GetBytes($val.ToString()) $bytesSent=$udpclient.Send($b,$b.length,$endpoint) ##Enviar un fichero y el hash "hola" | Out-File fichero.txt $val=Get-Content .\fichero.txt $b=[Text.Encoding]::ASCII.GetBytes($val.ToString()) $bytesSent=$udpclient.Send($b,$b.length,$endpoint) $val=(Get-FileHash .\fichero.txt).hash $b=[Text.Encoding]::ASCII.GetBytes($val.ToString()) $bytesSent=$udpclient.Send($b,$b.length,$endpoint) $udpclient.Close() |
