Last active
June 1, 2020 18:35
-
-
Save adamdriscoll/9d9ee5d2de627eec5c948b055772c7ba to your computer and use it in GitHub Desktop.
Send a command over a socket
This file contains hidden or 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
function Send-Socket { | |
param( | |
$IPAddress, | |
$Port, | |
$Command | |
) | |
$ipEndpoint = [System.Net.IPEndPoint]::new([System.Net.IPAddress]$IPAddress, $Port) | |
$socket = [System.Net.Sockets.Socket]::new($ipEndpoint.AddressFamily, 'Stream', 'TCP') | |
$socket.Connect($ipEndpoint) | |
$bytes = [System.Text.Encoding]::ASCII.GetBytes($Command) | |
$socket.Send($bytes, $bytes.Length, 0) | |
$socket.Dispose() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment