国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

在C#中使用Ping

2024-07-21 02:26:12
字體:
來源:轉載
供稿:網友


收集最實用的網頁特效代碼!

using system;
using system.diagnostics;

namespace consoleapplication7 {
 class class1 {

  [stathread]
  static void main(string[] args) {   
   string ip = "10.10.40.31";
   string strrst = cmdping(ip);
   console.writeline(strrst);
   console.readline();
  }

  private static string cmdping(string strip) {
   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("ping -n 1 "+strip);
   p.standardinput.writeline("exit");
   string strrst = p.standardoutput.readtoend();
   if(strrst.indexof("(0% loss)")!=-1)
    pingrst = "連接";
   else if( strrst.indexof("destination host unreachable.")!=-1)
    pingrst = "無法到達目的主機";
   else if(strrst.indexof("request timed out.")!=-1)
    pingrst = "超時";
   else if(strrst.indexof("unknown host")!=-1)
    pingrst = "無法解析主機";
   else
    pingrst = strrst;
   p.close();

   return pingrst;
  }
 }
}

上一篇:C#對話框

下一篇:C#還原數據庫

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 逊克县| 兰溪市| 青神县| 定边县| 张家界市| 平顺县| 黔西| 西和县| 绥中县| 繁峙县| 涡阳县| 正阳县| 辽阳市| 江阴市| 怀安县| 渭南市| 南漳县| 连江县| 卓尼县| 阜阳市| 天台县| 平罗县| 法库县| 贡觉县| 广丰县| 马公市| 吴江市| 顺昌县| 汝城县| 余庆县| 锦屏县| 马关县| 河北省| 黄山市| 曲沃县| 东源县| 股票| 电白县| 陇川县| 宣城市| 清新县|