ASP.NET Core使用Ping判断网络是否接通
发布时间:2020-12-16 07:32:33 所属栏目:asp.Net 来源:网络整理
导读:static void Main( string [] args) { // 主机地址 string targetHost = " bing.com " ; string data = " Hello world " ; Ping pingSender = new Ping(); PingOptions options = new PingOptions { DontFragment = true }; byte [] buffer = Encoding.ASCII
static void Main(string[] args) { // 主机地址 string targetHost = "bing.com"; string data = "Hello world"; Ping pingSender = new Ping(); PingOptions options = new PingOptions { DontFragment = true }; byte[] buffer = Encoding.ASCII.GetBytes(data); int timeout = 1024; Console.WriteLine($"Pinging {targetHost}"); //PingReply reply = pingSender.Send(targetHost,timeout,buffer,options); PingReply reply = pingSender.Send(targetHost,timeout); if (reply.Status == IPStatus.Success) { Console.WriteLine($"Address: {reply.Address}"); Console.WriteLine($"RoundTrip time: {reply.RoundtripTime}"); Console.WriteLine($"Time to live: {reply.Options.Ttl}"); Console.WriteLine($"Don‘t fragment: {reply.Options.DontFragment}"); Console.WriteLine($"Buffer size: {reply.Buffer.Length}"); } else { Console.WriteLine(reply.Status); } Console.ReadLine(); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – mvc asp.net中的自定义成员资格提供程序或配
- asp.net – 防止XSS(跨站脚本)
- asp.net-mvc – TDD:在ASP.NET MVC 3中测试DataAnnotation
- asp.net – 如何防止Entity Framework将FileStream列加载到
- asp.net – 仅包含所需参数的自定义MembershipUser
- asp.net – VB.NET接口
- asp.net – 将url参数添加到asp主题文件夹中的css文件中
- asp.net+Ajax 文本文件静态分页实现代码
- asp.net – 使用简单的ActionFilterAttribute运行时出错
- 在64位的环境中使用VS建立Web项目进行Oracle连接需要注意We
推荐文章
站长推荐
- asp.net-mvc – 模型在MVC中的作用是什么?
- asp.net-mvc – 部署后不显示捆绑的css … ASP.N
- asp.net – ViewState vs cookies vs cashing vs
- asp.net-mvc – ASP.NET MVC应用程序中的“坏二进
- asp.net – 格式化DataBinder.Eval数据
- asp.net – 允许远程访问IIS 7.5
- asp.net – 无法将第二个自引用FK添加到模型,导致
- wwwtl999999com17708846600Chinese exchangeto l
- 如何防止我的asp.net网站被屏幕刮掉?
- asp.net-web-api – 我可以在WebAPI messageHand
热点阅读