C#获得系统打开的端口和状态
实际是通过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#获得系统打开的端口和状态的更多相关文章
- 网络基本概念备忘:MAC地址,端口,HTTP状态码
MAC地址 英文MAC Address 英文全称: Media Access Control Address 别称:硬件位址 用途:定义网络设备位置 表示:十六进制数,6 Byte 特点:产品出产后M ...
- DATEADD和DATEDIFF函数、其他日期处理方法 、已打开的端口、FORMAT函数
DATEADD和DATEDIFF函数.其他日期处理方法 .已打开的端口.FORMAT函数 DATEADD和DATEDIFF函数.其他日期处理方法 .已打开的端口.Format函数 KeyLife富翁笔 ...
- windows 2012 服务器打开ping端口,开通远程连接
windows 2012 服务器打开ping端口,开通远程桌面连接 控制面板->系统与安全->高级防火墙->入站规则 找到:windows 远程桌面 (http in ) 右键启用 ...
- centos打开3306端口
centos默认是关闭了3306端口的,外网通过3306端口不能访问数据库,这时需呀打开3306端口1.打开端口: /sbin/iptables -I INPUT -p tcp --dport 330 ...
- CentOS7 firewalld 打开关闭端口
1. firewalld的基本使用 启动: systemctl start firewalld 关闭: systemctl stop firewalld 查看状态: systemctl status ...
- Linux系统打开core dump的配置【转】
什么是core dump core dump又叫核心转储, 当程序运行过程中发生异常, 程序异常退出时, 由操作系统把程序当前的内存状况存储在一个core文件中, 叫core dump.core du ...
- 阿里云centos7.x 打开80端口(转)
本文转自:https://blog.csdn.net/tengqingyong/article/details/82805053 一 :阿里云centos7.x用iptables打开80端口 1.安装 ...
- 系统安装SQL Sever2000后1433端口未开放,如何打开1433端口的解决方法
这篇文章主要针对Win2003系统安装SQL Sever2000后1433端口未开放,如何打开1433端口的解决方法. 用了几年的Windows2003和SQL Server2000了,不过这个问题倒 ...
- Linux系统 开通防火墙端口
Redhat 7内核 Linux系统 开通防火墙端口 使用systemctl 1.查看防火墙状态,root用户登录,执行命令systemctl status firewalld 2.开启防火墙:sy ...
随机推荐
- Android使用的Eclipse NDK开发较详细一篇文章
转自: http://www.cnblogs.com/zdz8207/archive/2012/11/27/android-ndk-install.html
- smarty中section遍历数组
smarty中section遍历数组
- 使用gulp插件来自动刷新页面。
http://itakeo.com/blog/2016/05/19/gulpreload/?none=123 使用gulp插件来自动刷新页面.再也不用修改一次,按一下F5了. 首选通过npm inst ...
- Verilog学习笔记基本语法篇(九)········ 任务和函数
task 和 function 说明语句分别用来定义任务和函数,利用任务和函数可以把函数模块分成许多小的任务和函数便于理解和调试.任务和函数往往还是大的程序模块在不同地点多次用到的相同的程序段.输入. ...
- C#属性: 利用set实现递归
直接帖代码: public class Bird { int xdata; /// <summary> /// 属性的简洁写法,等同于下面的xData方式 /// </summary ...
- C# 与 LUA 的经验对比
1,字符串遍历不同处:例: str = "汉字ABCabc"C#可以使用str[i]取得字符串中的汉字字符和拼音字符:Str[0] :汉Str[1]:字Str[2] : A依次类推 ...
- C++ 排序、查找的应用
// order.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include "string.h" #includ ...
- [CareerCup] 12.5 Test a Pen 测试一支笔
12.5 How would you testa pen? 这道题让我们测试一支笔,我们需要问面试官许多问题来理解"who,what,where,when,how and why" ...
- [CareerCup] 13.2 Compare Hash Table and STL Map 比较哈希表和Map
13.2 Compare and contrast a hash table and an STL map. How is a hash table implemented? If the numbe ...
- 《Linux内核设计与实现》课程学习重点问题总结
(问题均是同学提出或是老师上课重点讲解的部分内容,根据自身理解和笔记总结出自己的答案.如有不对,还请指教.) week2 [Q1]命令qemu -kernel 内核可执行文件 -initrd root ...