C#判断远程计算机的指定端口是否打开的代码

如下的内容段是关于C#判断远程计算机的指定端口是否打开的内容,应该能对小伙伴有一些用。

using System.Net;

if(!string.IsNullOrEmpty(txtPort.Text))

{

IPAddress ip = IPAddress.Parse(txtIp.Text);

IPEndPoint point=new IPEndPoint(ip,int.Parse(txtPort.Text));

try

{

TcpClient tcp=new TcpClient();

tcp.Connect(point);

MessageBox.Show("端口打开");

}catch(Exception ex)

{

MessageBox.Show(ex.Message);

}

}