當前位置:首頁 » 操作系統 » 控制台源碼

控制台源碼

發布時間: 2023-06-27 23:18:38

1. 用C#寫一個類似cmd的控制台程序,實現ping的功能!!!(求完整程序源代碼!)

using System;
using System.Net;
using System.Net.NetworkInformation;
class Program
{
static void Main(string[] args)
{
int count = 4;
IPAddress addr = IPAddress.Parse("220.181.111.86");
Ping ping = new Ping();
long timeSum = 0;
int succCount = 0;
//發送
Console.WriteLine("正在ping {0}", addr);
for (int i = 0; i < count; ++i)
{
PingReply pr = ping.Send(addr);
if (pr.Status == IPStatus.TimedOut)
Console.WriteLine("超時");
else if (pr.Status == IPStatus.Success)
{
Console.WriteLine("延時:{0}毫秒", pr.RoundtripTime);
++succCount;
timeSum += pr.RoundtripTime;
}
}
if (timeSum != 0)
Console.WriteLine("平均延時{0}毫秒,丟包率{1}%", 1.0 * timeSum / succCount, (count - succCount) * 100.0 / count);
else
Console.WriteLine("丟包率100%");
return;
}
}

2. 控制台C或者C++程序,列印出自身源代碼

#include <iostream>
#include <fstream>

#define FILENAME "example.cpp" // 這里指定文件名

using namespace std;

int main()
{
ifstream ifs(FILENAME);

char data[1024];

while (!ifs.eof())
{
ifs >> data;
cout << data;
}

ifs.close();
return 0;
}

熱點內容
java返回this 發布:2025-10-20 08:28:16 瀏覽:645
製作腳本網站 發布:2025-10-20 08:17:34 瀏覽:936
python中的init方法 發布:2025-10-20 08:17:33 瀏覽:632
圖案密碼什麼意思 發布:2025-10-20 08:16:56 瀏覽:821
怎麼清理微信視頻緩存 發布:2025-10-20 08:12:37 瀏覽:731
c語言編譯器怎麼看執行過程 發布:2025-10-20 08:00:32 瀏覽:1066
郵箱如何填寫發信伺服器 發布:2025-10-20 07:45:27 瀏覽:299
shell腳本入門案例 發布:2025-10-20 07:44:45 瀏覽:160
怎麼上傳照片瀏覽上傳 發布:2025-10-20 07:44:03 瀏覽:852
python股票數據獲取 發布:2025-10-20 07:39:44 瀏覽:763