powershell 脚本 - WINDOWS - 网络:测试网络连接/ Telnet替代方案

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell 脚本 - WINDOWS - 网络:测试网络连接/ Telnet替代方案相关的知识,希望对你有一定的参考价值。

function Test-Connection ($type, $ip, $port)
<#
 .SYNOPSIS
 Check network connection - alternative to Telnet
  
 .PARAMETER type
 The connection protocol either TCP or UDP.
 .PARAMETER ip
 The destination IP address
 .PARAMETER port
 The destination port
#>
{
    try {
        switch ($type) {
            "TCP" { (New-Object Net.Sockets.TcpClient).Connect($ip, $port) }
            "UDP" { (New-Object Net.Sockets.UdpClient).Connect($ip, $port) }
        }
        Write-Output "$($ip):$($port) $type - Connection established."
    } catch { Write-Output "$($ip):$($port) $type - Error connecting to host." }
}

<#
Write-Output "======================Configuration Manager================================="
Write-Output "***PDC2SCP001 - Primary Site Server***"
Test-Connection "TCP" "10.106.104.14" 80
Test-Connection "TCP" "10.106.104.14" 443
Test-Connection "TCP" "10.106.104.14" 445
Write-Output "***PDC2SUP003 - Software Update Point***"
Test-Connection "TCP" "10.106.104.103" 80
Test-Connection "TCP" "10.106.104.103" 443
Test-Connection "TCP" "10.106.104.103" 445
Test-Connection "TCP" "10.106.104.103" 8530
Test-Connection "TCP" "10.106.104.103" 8531
Write-Host "***PDC5SUP002  - Software Update Point***"
Test-Connection "TCP" "10.122.68.18" 80
Test-Connection "TCP" "10.122.68.18" 443
Test-Connection "TCP" "10.122.68.18" 445
Test-Connection "TCP" "10.122.68.18" 8530
Test-Connection "TCP" "10.122.68.18" 8531
Write-Output "***PDC2SDI003 - Distribution Point***"
Test-Connection "TCP" "10.106.104.12" 80
Test-Connection "TCP" "10.106.104.12" 443
Test-Connection "TCP" "10.106.104.12" 445
Write-Output "***PDC2SDI004 - Distribution Point***"
Test-Connection "TCP" "10.106.104.102" 80
Test-Connection "TCP" "10.106.104.102" 443
Test-Connection "TCP" "10.106.104.102" 445
Write-Host "***PDC5SDI002 - Distribution Point***"
Test-Connection "TCP" "10.122.68.16" 80
Test-Connection "TCP" "10.122.68.16" 443
Test-Connection "TCP" "10.122.68.16" 445
Write-Host "***PDC5SDI003 - Distribution Point***"
Test-Connection "TCP" "10.122.68.39" 80
Test-Connection "TCP" "10.122.68.39" 443
Test-Connection "TCP" "10.122.68.39" 445
#>

以上是关于powershell 脚本 - WINDOWS - 网络:测试网络连接/ Telnet替代方案的主要内容,如果未能解决你的问题,请参考以下文章

powershell Powershell脚本,用于在Windows中启用自然滚动

powershell 用于在Windows上运行东西的PowerShell脚本

windows主机开启winrm端口powershell脚本

windows主机开启winrm端口powershell脚本

Windows Powershell脚本执行

在 PowerShell 脚本中访问 Windows 任务凭据