麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 開發(fā) > PowerShell > 正文

PowerShell小技巧之發(fā)送TCP請求

2020-05-30 20:17:08
字體:
供稿:網(wǎng)友

很多時(shí)候我們需要通過Socket發(fā)送特定的TCP請求給服務(wù)器的特定端口來實(shí)現(xiàn)探測服務(wù)器的指定端口所開啟的服務(wù)。很多語言都有相應(yīng)的方法實(shí)現(xiàn)上述需求,當(dāng)然,PowerShell也不例外,比如我們要發(fā)送一個(gè)簡單的http請求到指定的web服務(wù)器:
GET / HTTP/1.1
Host:cn.bing.com

這里我們想請求微軟必應(yīng)的中文首頁,如果需要通過PowerShell向cn.bing.com服務(wù)器發(fā)送get請求,就需要?jiǎng)?chuàng)建一個(gè)System.Net.Sockets.TcpClient對象,向指定的服務(wù)器和端口發(fā)送請求。

具體代碼如下:

代碼如下:
        =====文件名:Send-TcpRequest.ps1=====
########################################
# Send-TcpRequest.ps1
## Send a TCP request to a remote computer, and return the response.
## If you do not supply input to this script (via either the pipeline, or the
## -InputObject parameter,) the script operates in interactive mode.
##
## Example:
##
## $http = @"
## GET / HTTP/1.1
## Host:cn.bing.com 
## `n`n
## "@
##
## $http | ./Send-TcpRequest cn.bing.com  80
########################################
param(
        [string] $remoteHost = "localhost",
        [int] $port = 80,
        [switch] $UseSSL,
        [string] $inputObject,
        [int] $commandDelay = 100
     )

[string] $output = ""

## Store the input into an array that we can scan over. If there was no input,
## then we will be in interactive mode.
$currentInput = $inputObject
if(-not $currentInput)
{
    $SCRIPT:currentInput = @($input)
}
$scriptedMode = [bool] $currentInput

function Main
{
    ## Open the socket, and connect to the computer on the specified port
    if(-not $scriptedMode)
    {
        write-host "Connecting to $remoteHost on port $port"
    }

    trap { Write-Error "Could not connect to remote computer: $_"; exit }
    $socket = new-object System.Net.Sockets.TcpClient($remoteHost, $port)

    if(-not $scriptedMode)
    {
        write-host "Connected. Press ^D followed by [ENTER] to exit.`n"
    }

    $stream = $socket.GetStream()

    if($UseSSL)
    {
        $sslStream = New-Object System.Net.Security.SslStream $stream,$false
        $sslStream.AuthenticateAsClient($remoteHost)

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 999精品国产 | 在线成人一区二区 | 在线成人一区二区 | 国产高潮好爽好大受不了了 | 亚洲第一精品在线 | 天天草夜夜 | 最新午夜综合福利视频 | 亚洲成人福利在线观看 | 国产精品999在线 | 成人免费毛片一 | 伊人久操视频 | 黄色成人短视频 | 一级做a爱片性色毛片高清 日本一区二区在线看 | 欧美aaa | 久久久久久久久成人 | 欧美国产成人在线 | 免费a级网站 | 99精品视频一区二区三区 | 欧美日韩在线中文字幕 | 亚洲一区 国产 | 怦然心动50免费完整版 | 久章草影院 | 久久久一二三 | 91羞羞| 亚洲国产小视频 | 精品国产91一区二区三区 | 中文字幕一区2区 | 精品国产一区二区三区久久久 | 免费久久久久久 | 免费观看黄色片视频 | 精品黑人一区二区三区国语馆 | 在火车上摸两乳爽的大叫 | 亚洲国产视频网 | 亚洲码无人客一区二区三区 | 中文字幕免费在线观看视频 | 视频一区二区三区在线播放 | 日本不卡一区二区三区在线观看 | 午夜视频在线观看免费视频 | 激情在线观看视频 | 国产日韩在线观看视频 | 久草最新在线 |