C#檢測遠(yuǎn)程計(jì)算機(jī)端口是否打開的方法
本文實(shí)例講述了C#檢測遠(yuǎn)程計(jì)算機(jī)端口是否打開的方法。分享給大家供大家參考。具體分析如下:
這段C#代碼用于檢測遠(yuǎn)程計(jì)算機(jī)的3389端口是否處理打開狀態(tài),可以根據(jù)實(shí)際需要設(shè)置其它端口
using System;
using System.Collections.Generic;
using System.Text;
using System.Net.NetworkInformation;
namespace test
{
class Program
{
static void Main(string[] args)
{
GetTcpConnections();
}
public static void GetTcpConnections()
{
IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();
TcpConnectionInformation[] connections = properties.GetActiveTcpConnections();
foreach (TcpConnectionInformation t in connections)
{
Console.Write("Local endpoint: {0} ", t.LocalEndPoint.ToString());
Console.Write("Remote endpoint: {0} ", t.RemoteEndPoint.ToString());
Console.WriteLine("{0}", t.State);
}
Console.WriteLine();
Console.ReadLine();
}
}
}
運(yùn)行結(jié)果如下:
Local endpoint: 127.0.0.1:1025 Remote endpoint: 127.0.0.1:1026 Established Local endpoint: 127.0.0.1:1026 Remote endpoint: 127.0.0.1:1025 Established Local endpoint: 127.0.0.1:1028 Remote endpoint: 127.0.0.1:16992 CloseWait Local endpoint: 127.0.0.1:1110 Remote endpoint: 127.0.0.1:4900 Established Local endpoint: 127.0.0.1:2754 Remote endpoint: 127.0.0.1:1110 CloseWait Local endpoint: 127.0.0.1:2762 Remote endpoint: 127.0.0.1:1110 CloseWait Local endpoint: 127.0.0.1:2773 Remote endpoint: 127.0.0.1:1110 CloseWait Local endpoint: 127.0.0.1:2913 Remote endpoint: 127.0.0.1:1110 CloseWait Local endpoint: 127.0.0.1:3014 Remote endpoint: 127.0.0.1:1110 CloseWait Local endpoint: 127.0.0.1:3531 Remote endpoint: 127.0.0.1:1110 CloseWait Local endpoint: 127.0.0.1:4012 Remote endpoint: 127.0.0.1:1110 CloseWait Local endpoint: 127.0.0.1:4900 Remote endpoint: 127.0.0.1:1110 Established
希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。
- c# 防火墻添加/刪除 特定端口的示例
- C#端口轉(zhuǎn)發(fā)用法詳解
- 基于C#實(shí)現(xiàn)的端口掃描器實(shí)例代碼
- c#檢測端口是否被占用的簡單實(shí)例
- C#獲取Windows進(jìn)程監(jiān)聽的TCP/UDP端口實(shí)例
- C#開發(fā)之Socket網(wǎng)絡(luò)編程TCP/IP層次模型、端口及報(bào)文等探討
- asp.net(c#)動(dòng)態(tài)修改webservice的地址和端口(動(dòng)態(tài)修改配置文件)
- c# 連接字符串?dāng)?shù)據(jù)庫服務(wù)器端口號(hào) .net狀態(tài)服務(wù)器端口號(hào)
- c# AcceptEx與完成端口(IOCP)結(jié)合的示例
相關(guān)文章
c#實(shí)現(xiàn)用SQL池,多線程定時(shí)批量執(zhí)行SQL語句的方法
構(gòu)建SQL池,分離業(yè)務(wù)邏輯層和數(shù)據(jù)訪問層,讓業(yè)務(wù)邏輯層從低效的數(shù)據(jù)庫操作解脫,以提高系統(tǒng)整體性能2013-10-10
C#中的SQLCommand命令與DbTransaction事務(wù)處理
這篇文章介紹了C#中的SQLCommand命令與DbTransaction事務(wù)處理,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-05-05
C#實(shí)現(xiàn)將字符串轉(zhuǎn)換成日期格式的方法
這篇文章主要介紹了C#實(shí)現(xiàn)將字符串轉(zhuǎn)換成日期格式的方法,涉及C#操作時(shí)間及字符串的相關(guān)技巧,非常簡單實(shí)用,需要的朋友可以參考下2015-05-05
C# 基于udp廣播收集局域網(wǎng)類所有設(shè)備信息
這篇文章主要介紹了C# 基于udp廣播收集局域網(wǎng)類所有設(shè)備信息的方法,幫助大家更好的理解和使用c#,感興趣的朋友可以了解下2020-12-12
Quartz.Net實(shí)現(xiàn)原理及使用方法詳解
這篇文章主要介紹了Quartz.Net實(shí)現(xiàn)原理及使用方法詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-12-12

