最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
asp.net 中调用cmd并查询IP信息
时间:2010-06-23 编辑:简简单单 来源:一聚教程网
asp.net 中调用cmd并查询ip信息
private static string cmdping(string cmd)
{
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;
string pingrst;
p.start();
p.standardinput.writeline(cmd);
p.standardinput.writeline("exit");
string strrst = p.standardoutput.readtoend();
pingrst = strrst;
// if end
p.close();
return pingrst;
}
//方法二
private string runcmd(string command)
{
//实例一个process类,启动一个独立进程
process p = new process();
//process类有一个startinfo属性,这个是processstartinfo类,包括了一些属性和方法,下面我们用到了他的几个属性:
p.startinfo.filename = "cmd.exe"; //设定程序名
p.startinfo.arguments = "/c " + command; //设定程式执行参数
p.startinfo.useshellexecute = false; //关闭shell的使用
p.startinfo.redirectstandardinput = true; //重定向标准输入
p.startinfo.redirectstandardoutput = true; //重定向标准输出
p.startinfo.redirectstandarderror = true; //重定向错误输出
p.startinfo.createnowindow = true; //设置不显示窗口
p.start(); //启动
//p.standardinput.writeline(command); //也可以用这种方式输入要执行的命令
//p.standardinput.writeline("exit"); //不过要记得加上exit要不然下一行程式执行的时候会当机
return p.standardoutput.readtoend(); //从输出流取得命令执行结果
//其它方法
system.net.dns.gethostaddresses("");
//这句就可以获取本机所有的ip地址了...
-
上一个: excel数据导入到dataset代码
-
下一个: asp.net 自动关机的代码
相关文章
- C#复制数组的两种方式及效率比较解读 10-24
- ASP.NET Identity用法解析 10-24
- ASP.NET MVC使用Identity增删改查用户介绍 10-24
- C语言中atoi函数模拟实现介绍 10-18
- .Net反向代理组件Yarp用法介绍 10-10
- .NET使用YARP通过编码方式配置域名转发实现反向代理教程 10-10