Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function tcping {
- param (
- [Parameter(Position=0)][string] $Server,
- [Parameter(Position=1)][string] $Port,
- [Parameter(Position=2)][int] $TimeOut = 2
- )
- if($Server -eq "") { $Server = Read-Host "Server" }
- if($Port -eq "") { $Port = Read-Host "Port" }
- if($Timeout -eq "") { $Timeout = 2 }
- [int]$TimeOutMS = $TimeOut*1000
- $IP = [System.Net.Dns]::GetHostAddresses($Server)
- $Address = [System.Net.IPAddress]::Parse($IP)
- $Socket = New-Object System.Net.Sockets.TCPClient
- Write-Host "Connecting to $Address on port $Port" -ForegroundColor Cyan
- Try {
- $Connect = $Socket.BeginConnect($Address,$Port,$null,$null)
- }
- Catch {
- Write-Host "$Server is NOT responding on port $Port" -ForegroundColor Red
- Write-Host ""
- Return $false
- Exit
- }
- Start-Sleep -Seconds $TimeOut
- if ( $Connect.IsCompleted )
- {
- $Wait = $Connect.AsyncWaitHandle.WaitOne($TimeOutMS,$false)
- if(!$Wait)
- {
- $Socket.Close()
- Write-Host "$Server is NOT responding on port $Port" -ForegroundColor Red
- Return $false
- }
- else
- {
- Try {
- $Socket.EndConnect($Connect)
- Write-Host "$Server IS responding on port $Port" -ForegroundColor Green
- Return $true
- }
- Catch { Write-Host "$Server is NOT responding on port $Port" -ForegroundColor Red }
- $Socket.Close()
- Return $false
- }
- }
- else
- {
- Write-Host "$Server is NOT responding on port $Port" -ForegroundColor Red
- Return $false
- }
- Write-Host ""
- }
- function waitrdp($server) {
- while((tcping -server $server -port 3389) -eq $false) {start-sleep -s 5}
- if(Test-Path "D:\Media\Sounds\Wav\Windows\TBONEWAH.WAV") {
- $sound = new-Object System.Media.SoundPlayer
- $sound.SoundLocation="D:\Media\Sounds\Wav\Windows\TBONEWAH.WAV"
- $sound.Play()
- }
- }
- function waithttp($server) {
- while((tcping -server $server -port 80) -eq $false) {start-sleep -s 5}
- if(Test-Path "D:\Media\Sounds\Wav\Windows\TBONEWAH.WAV") {
- $sound = new-Object System.Media.SoundPlayer
- $sound.SoundLocation="D:\Media\Sounds\Wav\Windows\TBONEWAH.WAV"
- $sound.Play()
- }
- }
- function waitssl($server) {
- while((tcping -server $server -port 443) -eq $false) {start-sleep -s 5}
- if(Test-Path "D:\Media\Sounds\Wav\Windows\TBONEWAH.WAV") {
- $sound = new-Object System.Media.SoundPlayer
- $sound.SoundLocation="D:\Media\Sounds\Wav\Windows\TBONEWAH.WAV"
- $sound.Play()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement