zoukankan      html  css  js  c++  java
  • 判断是否连网

    1、using System;

      using System.Collections.Generic;
      using System.Linq;
      using System.Text;
      using System.Net.NetworkInformation;
        
      namespace 判断是否联网
      {
          class Program
          {
              static void Main(string[] args)
              {
                  Ping p = new Ping();
                  PingReply pr;
        
                  pr = p.Send("119.75.218.45");//百度的IP
                  if (pr.Status != IPStatus.Success)//如果连接不成功
                  {
                      Console.WriteLine("未联网");
                  }
                  else
                  {
                      Console.WriteLine("已联网");
        
                  }
                  Console.Read();
        
              }
          }
      }

    2、

      WebRequest myrequest = WebRequest.Create("http://www.baidu.com");
                WebResponse myres = null;
                try
                {


                    myres = myrequest.GetResponse();
                    myres.Close();
                    MessageBox.Show("连上了");
                }
                catch (Exception)
                {


                    MessageBox.Show("连不上了");
                }

    3、

    public partial class Form1 : Form
    {
            //判断网络连接
            [DllImport("wininet")]
            private extern static bool InternetGetConnectedState(out int connectionDescription, int reservedValue);
            ///<summary>
            /// 检测本机的网络连接
            ///</summary>
     
           private void button1_Click(object sender, EventArgs e)
            {
                //判断是否联网
                    int i = 0;
                    if (InternetGetConnectedState(out i, 0))
                    {
                        //联网
                        MessageBox.Show("Thylx提醒您:你的计算机已连接到网络上!");
                     }
                     else
                      {
                         //断网
                         MessageBox.Show("Thylx提醒您:本地连接已断开!");
                      }
            }
    }

  • 相关阅读:
    ABAP术语-Logical Lock
    ABAP术语-Lock Object
    ABAP术语-Lock Mode
    ABAP术语-Lock Argument
    ABAP术语-Key Field
    Python面向对象基础-day6
    Python中的内置模块与生成器迭代器-day5
    Python高阶函数与函数装饰器-day4
    Python字符编码与函数基本使用-day3
    Nginx内置变量及正则语法
  • 原文地址:https://www.cnblogs.com/1175429393wljblog/p/5275723.html
Copyright © 2011-2022 走看看