如何检查网络端口访问并显示有用的消息? [英] How to check Network port access and display useful message?
本文介绍了如何检查网络端口访问并显示有用的消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正尝试使用powershell来检查端口是否打开,如下所示.
I was trying to check whether the port is opened or not using powershell like follows.
(new-object Net.Sockets.TcpClient).Connect("10.45.23.109", 443)
此方法有效,但是输出不是用户友好的.这意味着如果没有错误,则可以访问.有什么方法可以检查是否成功并显示诸如端口443处于运行状态"之类的消息?
This method works , but the output is not user-friendly. It means if there are no errors then it has access. Is there any way to check for success and display some message like " Port 443 is operational"?
推荐答案
实际上,谢伊·莱维(Shay levy)的回答几乎是正确的,但正如我在他的评论专栏中提到的那样,我遇到了一个奇怪的问题.因此,我将命令分为两行,效果很好.
Actually Shay levy's answer is almost correct but i got an weird issue as i mentioned in his comment column. So i split the command into two lines and it works fine.
$Ipaddress= Read-Host "Enter the IP address:"
$Port= Read-host "Enter the port number to access:"
$t = New-Object Net.Sockets.TcpClient
$t.Connect($Ipaddress,$Port)
if($t.Connected)
{
"Port $Port is operational"
}
else
{
"Port $Port is closed, You may need to contact your IT team to open it. "
}
这篇关于如何检查网络端口访问并显示有用的消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文