.NET:读取命令提示符输出
我想从 .net 调用 netsh
命令,我使用 Process
类来启动调用 netsh
命令的进程,及其工作正常,现在我想获取 .NET 中的 netsh
命令返回的输出,例如我在 Process
中调用以下命令:
netsh wlan show hostednetwork
这将返回列表活跃的托管网络。
如何读取 .NET 中的列表?
任何人都可以帮助我或带我走上正确的道路(我不想使用任何第三方工具)?
更新 下面是我使用 netsh wlan show Hostednetwork 命令的返回输出
托管网络设置
Mode : Allowed
SSID name : "AqaMaula(TUS)"
Max number of clients : 100
Authentication : WPA2-Personal
Cipher : CCMP
托管网络状态
Status : Started
BSSID : 06:65:9d:26:f4:b7
Radio type : 802.11n
Channel : 11
Number of clients : 1
d0:c1:b1:44:8b:f0 Authenticated
谁能告诉我如何获取所有单独数据并将它们放入数据库中,例如模式、SSID 名称等(单独)?
I want to call the netsh
command from .net, I am using the Process
class to initiate the process which calls the netsh
command, and its working fine, now I want to get the output returned by the netsh
command in .NET, for example I am calling the below command in Process
:
netsh wlan show hostednetwork
this is returning me the list of active hostednetwork.
How can I read the list in .NET?
Can anyone assist me or take me to the right path (I don't want to use any third party tools)?
UPDATES
Below is my return output using netsh wlan show hostednetwork command
Hosted network settings
Mode : Allowed
SSID name : "AqaMaula(TUS)"
Max number of clients : 100
Authentication : WPA2-Personal
Cipher : CCMP
Hosted network status
Status : Started
BSSID : 06:65:9d:26:f4:b7
Radio type : 802.11n
Channel : 11
Number of clients : 1
d0:c1:b1:44:8b:f0 Authenticated
Can anyone tell me how can i get all individual data and put them in database like, Mode, SSID Name, etc. (individually)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是代码:
更新
我认为您应该使用 托管 Wifi API 框架而不是解析命令行实用程序的结果。这是更可靠的方式。看一下源代码,它们包含 WifiExample。
Here is the code:
Update
I think you should use Managed Wifi API framework instead of parsing results of command line utility. It is more reliable way. Take a look at the sources, they contain WifiExample.
使用
StandardOutput
Process
类的属性。上面链接的 MSDN 页面附带了如何使用
StandardOutput
的简单示例。Use the
StandardOutput
property of theProcess
class.The above linked MSDN page comes with a simple example of how to use
StandardOutput
.在启动进程之前,您需要将
StartInfo.UseShellExecute
设置为 false,并将RedirectStandardOutput
设置为 true,然后从Process.StandardOutput
读取。所有内容均记录在 MSDN 上: http://msdn.microsoft .com/en-us/library/system.diagnostics.process.standardoutput.aspx
You need to set
StartInfo.UseShellExecute
to false andRedirectStandardOutput
to true before starting the process, and then read fromProcess.StandardOutput
.All documented on MSDN here: http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput.aspx
它应该是这样的:
不幸的是,我无法测试它来修复任何小错误。
另外,如果您要经常引用它们,我会在解析后将它们放入字典中,以减少查找时间。
It should be something like this:
Unfortunately, I can't test it atm to fix any small bugs.
Also, if you are going to reference them often, I'd place them into a Dictionary after parsing, to decrease lookup time.