欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PowerShell實(shí)現(xiàn)測(cè)試端口可用性腳本分享

 更新時(shí)間:2014年11月25日 16:31:30   投稿:junjie  
這篇文章主要介紹了PowerShell實(shí)現(xiàn)測(cè)試端口可用性腳本分享,本文腳本相對(duì)簡(jiǎn)單,使用TCP套接字實(shí)現(xiàn)需求,需要的朋友可以參考下

利用簡(jiǎn)單的TCP套接字來簡(jiǎn)單判斷一個(gè)端口是否可用:

復(fù)制代碼 代碼如下:

Function Test-PortAvailable
{
    param(
    [validaterange(1,65535)]
    [int]$Port
    )
    $sockt=New-Object System.Net.Sockets.Socket -ArgumentList 'InterNetwork','Stream','TCP'
    $ip = (Get-NetIPConfiguration).IPv4Address |
        Select -First 1 -ExpandProperty IPAddress
    $ipAddress = [Net.IPAddress]::Parse($ip)
    Try
    {
        $ipEndpoint = New-Object System.Net.IPEndPoint $ipAddress,$port
        $sockt.Bind($ipEndpoint)
        return $true
    }
    Catch [exception]
    {
        return $false
    }
    Finally
    {
        $sockt.Close()
    }
}

使用示例:

復(fù)制代碼 代碼如下:

PS> Test-PortAvailable -Port 102
True
PS> Test-PortAvailable -Port 1025
False

相關(guān)文章

最新評(píng)論