Powershell TCP connection script

From elyograg, 10 Months ago, written in PowerShell, viewed 90 times.
URL https://paste.elyograg.org/view/3e5796de Embed
Download Paste or View Raw
  1. $serverIP = "127.0.0.1"   # Replace with the IP address or hostname of the server
  2. $port = 80                # Replace with the port number you want to connect to
  3.  
  4. # Create a TCP client object
  5. $client = New-Object System.Net.Sockets.TcpClient
  6.  
  7. # Connect to the server
  8. $client.Connect($serverIP, $port)
  9.  
  10. if ($client.Connected) {
  11.     Write-Host "Connected to $serverIP on port $port"
  12.    
  13.     # Do further operations with the connection if required
  14.    
  15.     # Close the connection
  16.     $client.Close()
  17. }
  18. else {
  19.     Write-Host "Connection failed"
  20. }

Reply to "Powershell TCP connection script"

Here you can reply to the paste above