实际是通过c#编程方式调用了CMD命令行,然后调用netstat命令,然后将CMD命令的输出流转到了C#控制台程序上。也可以将结果输出到文件。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics; namespace _19获得系统打开的端口和状态
{
class Program
{
static void Main(string[] args)
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";//设置启动的应用程序
p.StartInfo.UseShellExecute = false;//禁止使用操作系统外壳程序启动进程
p.StartInfo.RedirectStandardInput = true;//应用程序的输入从流中读取
p.StartInfo.RedirectStandardOutput = true;//应用程序的输出写入流中
p.StartInfo.RedirectStandardError = true;//将错误信息写入流
p.StartInfo.CreateNoWindow = true;//是否在新窗口中启动进程
p.Start();
//p.StandardInput.WriteLine(@"netstat -a -n>c:\port.txt");//将字符串写入文本流
p.StandardInput.WriteLine(@"netstat -a -n");
string str;
while ((str = p.StandardOutput.ReadLine()) != null)
{
Console.WriteLine(str);
} Console.ReadKey();
}
}
}

C#获得系统打开的端口和状态的更多相关文章

  1. 网络基本概念备忘:MAC地址,端口,HTTP状态码

    MAC地址 英文MAC Address 英文全称: Media Access Control Address 别称:硬件位址 用途:定义网络设备位置 表示:十六进制数,6 Byte 特点:产品出产后M ...

  2. DATEADD和DATEDIFF函数、其他日期处理方法 、已打开的端口、FORMAT函数

    DATEADD和DATEDIFF函数.其他日期处理方法 .已打开的端口.FORMAT函数 DATEADD和DATEDIFF函数.其他日期处理方法 .已打开的端口.Format函数 KeyLife富翁笔 ...

  3. windows 2012 服务器打开ping端口,开通远程连接

    windows 2012 服务器打开ping端口,开通远程桌面连接 控制面板->系统与安全->高级防火墙->入站规则 找到:windows 远程桌面 (http in )  右键启用 ...

  4. centos打开3306端口

    centos默认是关闭了3306端口的,外网通过3306端口不能访问数据库,这时需呀打开3306端口1.打开端口: /sbin/iptables -I INPUT -p tcp --dport 330 ...

  5. CentOS7 firewalld 打开关闭端口

    1. firewalld的基本使用 启动: systemctl start firewalld 关闭: systemctl stop firewalld 查看状态: systemctl status ...

  6. Linux系统打开core dump的配置【转】

    什么是core dump core dump又叫核心转储, 当程序运行过程中发生异常, 程序异常退出时, 由操作系统把程序当前的内存状况存储在一个core文件中, 叫core dump.core du ...

  7. 阿里云centos7.x 打开80端口(转)

    本文转自:https://blog.csdn.net/tengqingyong/article/details/82805053 一 :阿里云centos7.x用iptables打开80端口 1.安装 ...

  8. 系统安装SQL Sever2000后1433端口未开放,如何打开1433端口的解决方法

    这篇文章主要针对Win2003系统安装SQL Sever2000后1433端口未开放,如何打开1433端口的解决方法. 用了几年的Windows2003和SQL Server2000了,不过这个问题倒 ...

  9. Linux系统 开通防火墙端口

    Redhat 7内核 Linux系统  开通防火墙端口 使用systemctl 1.查看防火墙状态,root用户登录,执行命令systemctl status firewalld 2.开启防火墙:sy ...

随机推荐

  1. delphi数组作为参数传值

    在函数中如果数组的个数不定,可以使用开放数组参数 实参可以接受静态数组和动态数组 procedure p1(a:array of Byte); begin ShowMessage( IntToHex( ...

  2. C语言 Linux内核链表(企业级链表)

    //Linux内核链表(企业级链表) #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> ...

  3. C#事件与接口

    using System; namespace ConsoleApplication1d { delegate void MsgDel(string s); interface IMsg { even ...

  4. PHP基础14:$_REQUEST

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. php基础11:运算符

    <?php $a = 5; $b = ++$a; echo '$a'.$a; echo "<br>"; echo '$b'.$b; echo "< ...

  6. WireShark系列: 使用WireShark过滤条件抓取特定数据流(zz)

    应用抓包过滤,选择Capture | Options,扩展窗口查看到Capture Filter栏.双击选定的接口,如下图所示,弹出Edit Interface Settints窗口. 下图显示了Ed ...

  7. LeetCode:Climbing Stairs(编程之美2.9-斐波那契数列)

    题目链接 You are climbing a stair case. It takes n steps to reach to the top. Each time you can either c ...

  8. Hibernate一级缓存与二级缓存的区别

    一级缓存: 就是Session级别的缓存.一个Session做了一个查询操作,它会把这个操作的结果放在一级缓存中. 如果短时间内这个session(一定要同一个session)又做了同一个操作,那么h ...

  9. 『转载』C# winform 中dataGridView的重绘(进度条,虚线,单元格合并等)

    原文转载自:http://hi.baidu.com/suming/item/81e45b1ab9b4585f2a3e2243 最近比较浅的研究了一下dataGridView的重绘,发现里面还是有很多东 ...

  10. selection伪元素小解

    上一篇:<RGBA与Opacity区别小解> p{font-size:14px;} 今天说一个简单的伪元素::selection,它的用武之地仅在于改变选中文本时文本的颜色和文本背景颜色. ...