Bind and connect to TCP socket using PowerShell

  • Bind
    $Listener = [System.Net.Sockets.TcpListener]443
    $Listener.Start()
    while($true) {
        $client = $Listener.AcceptTcpClient()
        Write-Host "Connection received!"
        $client.Close()
    }
  • Connect
    (New-Object Net.Sockets.TcpClient).Connect('192.0.2.1', 443)