arp -a和路由打印 [英] arp -a and route print

查看:108
本文介绍了arp -a和路由打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写一个显示此信息的程序:

  • netstat
  • TCP/UDP连接
  • 有关IP ipconfig/all的信息
  • arp-a
  • 路线打印

我已经拥有大多数,但是我在route printarp -a上遇到了问题.我不想使用Process.Start()执行此命令,因为它看起来不太壮观:

Process p = new Process ();

p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.UseShellExecute = false;
p.StartInfo.FileName = "route";
p.StartInfo.Arguments = "PRINT";
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.StandardOutputEncoding = Encoding.Default;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.Start();
TextBox1.Text = p.StandardOutput.ReadToEnd();

我想使用一个foreach循环将数据获取到ListView或DataGrid列中.有人可以帮助我吗?我如何将这些数据放入每一列:目标,网络掩码,网关,接口,度量和永久路由?对于ARP, 物理地址的互联网地址类型?

解决方案

我想您可能只需解析检索到的文本,以获取所需的值并将其放在ListView等中.但是,我认为有更好的方法来检索此信息,我认为您可以使用WMI类 WMI代码创建器v1.0 可帮助您入门(我自己没有使用过,但是我看到有人在某个时候建议使用它).

WMI .NET概述可能也很有用. /p>

I need to write a program that displays this information:

  • netstat
  • TCP / UDP connections
  • Information about the IP ipconfig /all
  • arp-a
  • route print

I already have most of them, but I have a problem with the route print and arp -a. I do not want to execute this command using Process.Start() because it does not look too spectacular:

Process p = new Process ();

p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.UseShellExecute = false;
p.StartInfo.FileName = "route";
p.StartInfo.Arguments = "PRINT";
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.StandardOutputEncoding = Encoding.Default;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.Start();
TextBox1.Text = p.StandardOutput.ReadToEnd();

I would like to use a foreach loop to get the data into ListView or DataGrid columns. Has anyone ~ t be able to help me? How can I get this data into each column: Destination, Netmask, gateway, interface, metrics and permanent route? And in the case of ARP, Internet address type of physical address?

解决方案

I suppose you could probably just parse the text you retrieve to get out the values you want and put them in the ListView etc. However, I think that there are better ways to retrieve this and I think you'd be able to get out this information using the WMI class Win32_IP4RouteTable.

If you haven't used WMI before, you might be able to use the WMI Code Creator v1.0 to help you get started (I haven't used it myself, but I saw someone else suggesting it sometime).

The WMI .NET Overview would probably be useful too.

这篇关于arp -a和路由打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆