
正文
vb.net监控端口 vbnet console
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
vb.net 指定IP端口是否开放
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);
}
}
通过以上这个方法,只能判断你是否能链接这个端口。
通过以下这个方法,能判断端口是否开放
public static void GetTcpConnections()
{
IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();
TcpConnectionInformation[] connections = properties.GetActiveTcpConnections();
string str="";
foreach (TcpConnectionInformation t in connections)
{
str+="Local endpoint:"+ t.LocalEndPoint.ToString()+",";
str+="Remote endpoint:"+ t.RemoteEndPoint.ToString()+",";
str+=t.State.ToString()+",";
}
MessageBox.Show(str);
}
相关问答
Q1: VB与VB.NET串口及以太网通迅
关于串口通讯的问题:
很明显,你还不知道(不会、不习惯)使用事件驱动的方式接收数据。
建议你仔细看看串口组件(无论VB6还是VB.net)的OnComm事件,你的问题很容易解决。
关于以太网通讯:
在TCP通讯中端口确实可以重用,你百度一下“TCP端口重用”能查到很多示例。
但绝大多数情况下不推荐端口重用,而应该采取服务器端建立连接池的方法。
或者,干脆不用TCP,用UDP解决也可以。
Q2: vb.net中如何设计一个监控程序?
以记事本为例
Public Class Form1
Public Sub ShellAndWait(ByVal ProcessPath As String)
Dim objProcess As System.Diagnostics.Process
Try
objProcess = New System.Diagnostics.Process()
objProcess.StartInfo.FileName = ProcessPath
objProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal
objProcess.Start()
objProcess.WaitForExit()
objProcess.Close()
Catch
MessageBox.Show("无法执行文件 " ProcessPath, "错误")
End Try
End Sub
'监视程序就可以了,若果监视别的窗体的话,用SPY++ 找到句柄,配合FindWindowEx,SendMessage根据其属性做
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ShellAndWait("Notepad.exe")
MessageBox.Show("笔记本被关闭后我才会出现")
End Sub
End Class
Q3: vb.net在哪个工具栏可以找到监视窗口
2005程序运行到断点处,右键可以添加到监视窗口。
一般都可以在工具--自定义里找到。
vb.net监控端口的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于vbnet console、vb.net监控端口的信息别忘了在本站进行查找喔。








