| 12345678910111213141516171819202122232425 |
- # Test port connectivity to 125.122.32.114:9000
- $target = "125.122.32.114"
- $port = 9000
- Write-Host "Testing connection to $target`:$port..." -ForegroundColor Cyan
- try {
- $tcpClient = New-Object System.Net.Sockets.TcpClient
- $connect = $tcpClient.BeginConnect($target, $port, $null, $null)
- $wait = $connect.AsyncWaitHandle.WaitOne(5000, $false) # 5 second timeout
- if ($wait) {
- $tcpClient.EndConnect($connect)
- $tcpClient.Close()
- Write-Host "SUCCESS: Port $port is reachable on $target" -ForegroundColor Green
- exit 0
- } else {
- $tcpClient.Close()
- Write-Host "FAILED: Connection timed out after 5 seconds" -ForegroundColor Red
- exit 1
- }
- } catch {
- Write-Host "FAILED: Unable to connect - $_" -ForegroundColor Red
- exit 1
- }
|