new push
This commit is contained in:
80
Conversation.ps1
Normal file
80
Conversation.ps1
Normal file
@@ -0,0 +1,80 @@
|
||||
## After running the powershell scriopt run the following after the fact changing the port number to what you need.
|
||||
|
||||
## $msg = Receive-TCPMessage -Port 9999
|
||||
|
||||
## from the remote server that you need to send the traffic from. Run the following with the port number you set to listen
|
||||
|
||||
## Test-NetConnection win1962 -Port 9999
|
||||
|
||||
Function Receive-TCPMessage {
|
||||
|
||||
Param (
|
||||
|
||||
[Parameter(Mandatory=$true, Position=0)]
|
||||
|
||||
[ValidateNotNullOrEmpty()]
|
||||
|
||||
[int] $Port
|
||||
|
||||
)
|
||||
|
||||
Process {
|
||||
|
||||
Try {
|
||||
|
||||
# Set up endpoint and start listening
|
||||
|
||||
$endpoint = new-object System.Net.IPEndPoint([ipaddress]::any,$port)
|
||||
|
||||
$listener = new-object System.Net.Sockets.TcpListener $EndPoint
|
||||
|
||||
$listener.start()
|
||||
|
||||
|
||||
|
||||
# Wait for an incoming connection
|
||||
|
||||
$data = $listener.AcceptTcpClient()
|
||||
|
||||
|
||||
|
||||
# Stream setup
|
||||
|
||||
$stream = $data.GetStream()
|
||||
|
||||
$bytes = New-Object System.Byte[] 1024
|
||||
|
||||
|
||||
|
||||
# Read data from stream and write it to host
|
||||
|
||||
while (($i = $stream.Read($bytes,0,$bytes.Length)) -ne 0){
|
||||
|
||||
$EncodedText = New-Object System.Text.ASCIIEncoding
|
||||
|
||||
$data = $EncodedText.GetString($bytes,0, $i)
|
||||
|
||||
Write-Output $data
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
# Close TCP connection and stop listening
|
||||
|
||||
$stream.close()
|
||||
|
||||
$listener.stop()
|
||||
|
||||
}
|
||||
|
||||
Catch {
|
||||
|
||||
"Receive Message failed with: `n" + $Error[0]
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user