[玩转系统] PowerShell 测试-NetConnection | PowerShell Test-NetConnection 指南
作者:精品下载站 日期:2024-12-14 04:59:10 浏览:15 分类:玩电脑
PowerShell 测试-NetConnection | PowerShell Test-NetConnection 指南
PowerShell Test-NetConnection简介
测试网连接用于与连接相关的各种信息,例如诊断和连接性。在 PowerShell v4.0 之前,有不同的工具可用于解决与网络相关的不同问题。为了避免这种情况,引入了此 cmdlet 作为单点源来解决各种与连接相关的问题。此 cmdlet 支持的各种诊断包括路由跟踪和选择诊断、ping 和 TCP。根据提供的输入,输出范围包括各种信息,例如 DNS 查找结果、配置的各种 IP 地址和安全规则、源和目标 IP 地址选择结果以及与连接相关的信息。本文将详细介绍测试网连接、其参数及其用法。
语法:
NAME
Test-NetConnection
语法:
Test-NetConnection [[-ComputerName] <string>] [-TraceRoute] [-Hops <int>] [-InformationLevel {Quiet | Detailed}]
[<CommonParameters>]
Test-NetConnection [[-ComputerName] <string>] [-CommonTCPPort] {HTTP | RDP | SMB | WINRM} [-InformationLevel {Quiet | Detailed}]
[<CommonParameters>]
Test-NetConnection [[-ComputerName] <string>] -Port <int> [-InformationLevel {Quiet | Detailed}] [<CommonParameters>]
Test-NetConnection [[-ComputerName] <string>] -DiagnoseRouting [-ConstrainSourceAddress <string>] [-ConstrainInterface <uint32>]
[-InformationLevel {Quiet | Detailed}] [<CommonParameters>]
ALIASES
TNC
例如:
输入:
Test-NetConnection
输出:
PowerShell Test-NetConnection 的参数
- CommonTcpPort:
这表示要检查的 tcp 端口号。该参数的数据类型是字符串。这不是强制参数。该cmdlet中参数的位置是1。它不接受pipline和通配符作为输入。此参数唯一可接受的值是 SMB、HTTP、WINRM 和 HTTP。
- 计算机名称:
这指定目标系统的 DNS 或 IP 地址。该参数的数据类型为字符串。也可以使用RemoteAddress、cn 进行引用。此参数在 cmdlet 中的位置为零。默认值为无。它接受管道输入,但不允许使用通配符。
- -约束接口:
这表示过去用于诊断路由的机制。该参数的数据类型为Uint32。默认值为无。它不接受管道字符和通配符作为输入。
- -约束源地址:
这表示用于诊断源地址的约束。该参数的数据类型为字符串。默认值为无。它不接受管道字符和通配符作为输入。
- -诊断路由:
这表示诊断从源运行到目标。该参数的数据类型为字符串。默认值为无。它不接受管道字符和通配符作为输入。
- -啤酒花:
这表示作为遍历跟踪路由 cmdlet 的一部分应执行的跳转次数。该参数的数据类型为int32。默认值为无。它不接受管道字符和通配符作为输入。
- -信息级别:
这表示应显示的信息类型。该参数的数据类型是字符串。默认值为无。它不接受管道字符和通配符作为输入。以下是可以提供给此参数的值;细致而安静。如果值为quiet,则仅返回基本信息。
- -端口:
这表示要检查连接的远程计算机的端口号。也可以参考使用Remoteport。该参数的数据类型为int32。默认值为无。它接受管道输入,但不允许使用通配符。
- -跟踪路线:
这表示在目标计算机上运行的连接测试。该参数的数据类型为switch。默认值为 none 它不接受管道字符和通配符作为输入。
在Test-Netconnection之前,之前的版本是Test-Connection。它具有缓冲区大小和延迟等参数,可用于定义连续 ping 之间的秒数。
示例
让我们讨论 PowerShell Test-NetConnection 的示例。
示例#1:获取详细且安静的信息
输入:
Write-Host "Welcome to demo of test-netconnection" -ForegroundColor Green
Write-Host "Running the command with informational level"
$infolevel=Read-Host "specify the information level"
Write-Host "The speified information level is" $infolevel -ForegroundColor Green
Test-NetConnection -InformationLevel $infolevel
$infolevel=Read-Host "specify the information level"
Write-Host "The speified information level is" $infolevel -ForegroundColor Green
Test-NetConnection -InformationLevel $infolevel
输出:
安静信息级别仅返回二进制值。如果连接成功则返回 true,如果连接不存在则返回 false。
例子#2
使用端口号检查远程连接并 ping 远程服务器
输入:
Write-Host "testing conenction using port number" -ForegroundColor Green
$infolevel= Read-Host "Enter the information level to be used"
$portno= Read-Host "Enter the port no to check"
Write-Host "The details are as follows" -ForegroundColor Green
Test-NetConnection -Port $portno -InformationLevel $infolevel
Write-Host "Demo of reching out to remote computer"
$remotecmp= Read-Host "Enter the remote computer details"
$infolevel1= Read-Host "Enter the info level to be used"
Write-Host "The details are as follows" -ForegroundColor Green
Test-NetConnection -ComputerName $remotecmp -InformationLevel $infolevel1
输出:
例子#3
输入:
Write-Host "Demo to see if a port is open" -ForegroundColor Green
$rs= Read-Host "enter the remote server"
Test-NetConnection -ComputerName $rs -CommonTCPPort HTTP
$portno=Read-Host "enter the port no"
$ipadd= Read-Host "enter the ip address"
$con = New-Object System.Net.Sockets.TcpClient($ipadd, $portno)
if ($connection.Connected) {
Write-Host "connection is succeeded" -ForegroundColor Green
} else {
Write-Host "connection is failed" -ForegroundColor Red
}
输出:
例子#4
输入:
Write-Host "Demo of trace route in test-netonnection"
$servername= Read-Host "enter the server name"
Test-NetConnection -ComputerName $servername -TraceRoute
Write-Host "With detailed information" -ForegroundColor Green
Test-NetConnection -ComputerName $servername -TraceRoute -InformationLevel Detailed
Write-Host "demo of diagnostic routing"
$sname= Read-Host "enter the site address"
Test-NetConnection -ComputerName $sname -DiagnoseRouting
Write-Host "With detailed information" -ForegroundColor Green
Test-NetConnection -ComputerName $sname -DiagnoseRouting -InformationLevel Detailed
输出:
结论
因此,本文详细解释了 Test-NetcOnnection cmdlet。它涵盖了可以使用它的各种场景以及适当的示例。它还解释了与 cmdlet 关联的各种参数。要详细了解更多信息,建议编写并执行示例脚本。
猜你还喜欢
- 03-30 [玩转系统] 如何用批处理实现关机,注销,重启和锁定计算机
- 02-14 [系统故障] Win10下报错:该文件没有与之关联的应用来执行该操作
- 01-07 [系统问题] Win10--解决锁屏后会断网的问题
- 01-02 [系统技巧] Windows系统如何关闭防火墙保姆式教程,超详细
- 12-15 [玩转系统] 如何在 Windows 10 和 11 上允许多个 RDP 会话
- 12-15 [玩转系统] 查找 Exchange/Microsoft 365 中不活动(未使用)的通讯组列表
- 12-15 [玩转系统] 如何在 Windows 上安装远程服务器管理工具 (RSAT)
- 12-15 [玩转系统] 如何在 Windows 上重置组策略设置
- 12-15 [玩转系统] 如何获取计算机上的本地管理员列表?
- 12-15 [玩转系统] 在 Visual Studio Code 中连接到 MS SQL Server 数据库
- 12-15 [玩转系统] 如何降级 Windows Server 版本或许可证
- 12-15 [玩转系统] 如何允许非管理员用户在 Windows 中启动/停止服务
取消回复欢迎 你 发表评论:
- 精品推荐!
-
- 最新文章
- 热门文章
- 热评文章
[影视] 黑道中人 Alto Knights(2025)剧情 犯罪 历史 电影
[古装剧] [七侠五义][全75集][WEB-MP4/76G][国语无字][1080P][焦恩俊经典]
[实用软件] 虚拟手机号 电话 验证码 注册
[电视剧] 安眠书店/你 第五季 You Season 5 (2025) 【全10集】
[电视剧] 棋士(2025) 4K 1080P【全22集】悬疑 犯罪 王宝强 陈明昊
[软件合集] 25年6月5日 精选软件22个
[软件合集] 25年6月4日 精选软件36个
[短剧] 2025年06月04日 精选+付费短剧推荐33部
[短剧] 2025年06月03日 精选+付费短剧推荐25部
[软件合集] 25年6月3日 精选软件44个
[剧集] [央视][笑傲江湖][2001][DVD-RMVB][高清][40集全]李亚鹏、许晴、苗乙乙
[电视剧] 欢乐颂.5部全 (2016-2024)
[电视剧] [突围] [45集全] [WEB-MP4/每集1.5GB] [国语/内嵌中文字幕] [4K-2160P] [无水印]
[影视] 【稀有资源】香港老片 艺坛照妖镜之96应召名册 (1996)
[剧集] 神经风云(2023)(完结).4K
[剧集] [BT] [TVB] [黑夜彩虹(2003)] [全21集] [粤语中字] [TV-RMVB]
[实用软件] 虚拟手机号 电话 验证码 注册
[资源] B站充电视频合集,包含多位重量级up主,全是大佬真金白银买来的~【99GB】
[影视] 内地绝版高清录像带 [mpg]
[书籍] 古今奇书禁书三教九流资料大合集 猎奇必备珍藏资源PDF版 1.14G
[电视剧] [突围] [45集全] [WEB-MP4/每集1.5GB] [国语/内嵌中文字幕] [4K-2160P] [无水印]
[剧集] [央视][笑傲江湖][2001][DVD-RMVB][高清][40集全]李亚鹏、许晴、苗乙乙
[电影] 美国队长4 4K原盘REMUX 杜比视界 内封简繁英双语字幕 49G
[电影] 死神来了(1-6)大合集!
[软件合集] 25年05月13日 精选软件16个
[精品软件] 25年05月15日 精选软件18个
[绝版资源] 南与北 第1-2季 合集 North and South (1985) /美国/豆瓣: 8.8[1080P][中文字幕]
[软件] 25年05月14日 精选软件57个
[短剧] 2025年05月14日 精选+付费短剧推荐39部
[短剧] 2025年05月15日 精选+付费短剧推荐36部
- 最新评论
-
- 热门tag