打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
[C#] 调用CMD,获取系统中的端口列表
                listBox_port.Items.Clear();                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 -an");
                p.StandardInput.WriteLine("exit");

                string info = p.StandardOutput.ReadToEnd();
                File.WriteAllText("port.txt", info);
         
            try
            {
                string[] port = File.ReadAllLines("port.txt");
                 for (int i = 8; i < port.Length - 1; i++)
                 {
                     listBox_port.Items.Add(port[i]);
                     string[] ports = port[i].Substring(0, 30).Split(':');
                     ListViewItem item = new ListViewItem();
                     item.Text = ports[1];
                     item.SubItems.Add(port[i].Substring(0, 5));
                     try
                     {
                         item.SubItems.Add(port[i].Substring(54, port[i].Length-54));
                     }
                     catch 
                     {
                         item.SubItems.Add("暂无");
                     }
                     listView_port.Items.Add(item);
                 }

            }
            catch { }
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
C# ListView控件的使用方法 简介
[Unity3d]C#调用WINDOWS命令行(CMD)
总结C#启动外部程序的几种方法
C#—ListView控件
C# 调用adb command 读取手机型号和IMEI
C#启动进程之Process
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服