test-port.ps1 804 B

12345678910111213141516171819202122232425
  1. # Test port connectivity to 125.122.32.114:9000
  2. $target = "125.122.32.114"
  3. $port = 9000
  4. Write-Host "Testing connection to $target`:$port..." -ForegroundColor Cyan
  5. try {
  6. $tcpClient = New-Object System.Net.Sockets.TcpClient
  7. $connect = $tcpClient.BeginConnect($target, $port, $null, $null)
  8. $wait = $connect.AsyncWaitHandle.WaitOne(5000, $false) # 5 second timeout
  9. if ($wait) {
  10. $tcpClient.EndConnect($connect)
  11. $tcpClient.Close()
  12. Write-Host "SUCCESS: Port $port is reachable on $target" -ForegroundColor Green
  13. exit 0
  14. } else {
  15. $tcpClient.Close()
  16. Write-Host "FAILED: Connection timed out after 5 seconds" -ForegroundColor Red
  17. exit 1
  18. }
  19. } catch {
  20. Write-Host "FAILED: Unable to connect - $_" -ForegroundColor Red
  21. exit 1
  22. }