最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
asp.net 中调用cmd并查询IP信息
时间:2022-06-25 05:07:45 编辑:袖梨 来源:一聚教程网
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地址了...
相关文章
- 金铲铲之战幻灵武器选择推荐 07-01
- 崩坏星穹铁道斯缇科西亚若虫位置一览 07-01
- 洛克王国世界机甲小子捕捉方法 07-01
- XRoad(XRI币)排名是什么 07-01
- 金铲铲之战s14街头恶魔主c阵容构筑推荐 07-01
- 魔兽世界11.1雷鼓哑炮火箭怎么获得 07-01