本文最后更新于 14 天前,如有失效请评论区留言。
简介:
一款轻量级一键清理电脑DNS缓存的小工具,解决电脑因为DNS问题引起的网络问题。
前言:
C#的的第一个练手项目,主要是练习一下基本功,提供源代码和编译好的.exe程序,供各位下载的编译,新手上路大佬勿喷。。。
界面预览:
源代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Threading;
namespace DNS_cache_cleaner_tool
{
class Program
{
static void Main(string[] args)
{
Console.Title = "DNS Cache Cleaner Tool C#";
Process p = new Process();
//设置要启动的应用程序
p.StartInfo.FileName = "cmd.exe";
//是否使用操作系统shell启动
p.StartInfo.UseShellExecute = false;
// 接受来自调用程序的输入信息
p.StartInfo.RedirectStandardInput = true;
//输出信息
p.StartInfo.RedirectStandardOutput = true;
//输出错误
p.StartInfo.RedirectStandardError = true;
//不显示程序窗口
p.StartInfo.CreateNoWindow = true;
//启动程序
p.Start();
Console.WriteLine("是否清理DNS缓存(y/n):");
string User_txt = Console.ReadLine();
//Console.WriteLine("用户输入:" + User_txt);
if (User_txt == "y")
{
//Console.WriteLine("开始清理DNS缓存...");
//声明一个名为strInput的string变量并给其赋值
string strInput = "ipconfig/flushdns";
//向cmd窗口发送输入信息
p.StandardInput.WriteLine(strInput + "&exit");
p.StandardInput.AutoFlush = true;
//获取输出信息
string strOuput = p.StandardOutput.ReadToEnd();
//等待程序执行完退出进程
p.WaitForExit();
p.Close();
//输出控制台返回信息
//Console.WriteLine(strOuput);
//定义一个名为PD的bool类型变量并赋值,bool类型存储true或false
bool PD = strOuput.Contains("已成功刷新 DNS 解析缓存。");
if (PD == true)
{
Console.WriteLine("清理完成!");
Console.WriteLine("程序将在2秒后退出...");
Thread.Sleep(2000);
//Console.ReadKey();
}
else
{
Console.WriteLine("清理失败!");
Console.WriteLine("程序将在2秒后退出...");
Thread.Sleep(2000);
//Console.ReadKey();
}
}
else
{
Console.WriteLine("程序将在2秒后退出...");
Thread.Sleep(2000);
}
}
}
}
下载区:
类型 | 地址 | 提取码 |
.exe | https://wankesixiang.lanzoub.com/i8naF2qngguj | aw6k |