Untitled

mail@pastecode.io avatar
unknown
plain_text
25 days ago
2.1 kB
2
Indexable
Never
# Function to check if a port is open using Test-NetConnection
function Check-Port {
    param (
        [string]$domain,
        [int]$port,
        [string]$protocol
    )

    # For UDP protocol, we use Test-NetConnection with the -UdpPort parameter
    if ($protocol -eq "UDP") {
        $result = Test-NetConnection -ComputerName $domain -Port $port -UdpPort -WarningAction SilentlyContinue
    } else {
        $result = Test-NetConnection -ComputerName $domain -Port $port -WarningAction SilentlyContinue
    }

    # Check if the port is open or blocked
    if ($protocol -eq "TCP" -and $result.TcpTestSucceeded -eq $false) {
        $script:blocked_ports += "$domain ($protocol): $port"
    } elseif ($protocol -eq "UDP" -and $result.UdpTestSucceeded -eq $false) {
        $script:blocked_ports += "$domain ($protocol): $port"
    }
}

# Initialize blocked_ports array
$script:blocked_ports = @()

# Total number of ports to check
$total_ports = 1 + 2 + (65535 - 49152 + 1) # STUN + 2 signaling + UDP range
$current_port = 0

# Check STUN/TURN Servers
$stun_ports = @(3478)
foreach ($port in $stun_ports) {
    $current_port++
    Write-Host "[$current_port/$total_ports] Checking STUN port $port..."
    Check-Port -domain "remoteviewer.esper.cloud" -port $port -protocol "TCP"
}

# Check Signaling Ports
$signaling_ports = @(80, 443)
foreach ($port in $signaling_ports) {
    $current_port++
    Write-Host "[$current_port/$total_ports] Checking signaling port $port..."
    Check-Port -domain "status.esper.cloud" -port $port -protocol "TCP"
}

# Check Media Ports (Dynamic Range)
foreach ($port in 49152..65535) {
    $current_port++
    Write-Host "[$current_port/$total_ports] Checking UDP port $port..."
    Check-Port -domain "remoteviewer.esper.cloud" -port $port -protocol "UDP"
}

# Final output
Write-Host

# Display blocked ports if any
if ($script:blocked_ports.Count -eq 0) {
    Write-Host "Port checking complete: all ports are open. 🎉"
} else {
    Write-Host "Port checking complete: Blocked or unreachable ports:"
    foreach ($port in $script:blocked_ports) {
        Write-Host "❌ $port"
    }
}
Leave a Comment