lixiaojun
2022-09-02 d5a3d08601fa59498edc092cec23c7ca166a0d15
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
 
namespace IStation.Untity
{
    /// <summary>
    /// 网络工具类
    /// </summary>
    public class InternetHelper
    {
        private const int INTERNET_CONNECTION_MODEM = 1;
        private const int INTERNET_CONNECTION_LAN = 2;
        private const int INTERNET_CONNECTION_PROXY = 4;
        private const int INTERNET_CONNECTION_MODEM_BUSY = 8;
 
        ///导入判断网络是否连接的 .dll  
        [DllImport("wininet.dll", EntryPoint = "InternetGetConnectedState")]
 
 
        /// <summary>   
        /// 判断网络状况的方法,返回值true为连接,false为未连接 
        /// </summary>   
        /// <param name="conState"> </param>   
        /// <param name="reder"> </param>   
        public extern static bool InternetGetConnectedState(out int conState, int reder);
 
        /*使用方法
            var internetCode = 0;
            var hasInternet = InternetUtils.InternetGetConnectedState(out internetCode, 0);
            if (!hasInternet)
            {
                XtraMessageBox.Show("当前未连接网络!");
                return;
            }
        */
 
        //int dwFlag = 0;
        //string netstatus = "";
        //if (!InternetGetConnectedState(ref dwFlag, 0))
        //Console.WriteLine("未联网!");
        //else
        //{
        //if ((dwFlag & INTERNET_CONNECTION_MODEM) != 0)
        //netstatus += " 采用调治解调器上网 /n";
        //if ((dwFlag & INTERNET_CONNECTION_LAN) != 0)
        //netstatus += " 采用网卡上网 /n";
        //if ((dwFlag & INTERNET_CONNECTION_PROXY) != 0)
        //netstatus += " 采用代理上网 /n";
        //if ((dwFlag & INTERNET_CONNECTION_MODEM_BUSY) != 0)
        //netstatus += " MODEM被其他非INTERNET连接占用 /n";
        //}
 
 
 
    }
}