1
wxr
2023-03-31 7e42cc13a14b7de31c9f5d5c61cdf24f3246335d
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
 
using System.Net.Sockets;
using System.Net.NetworkInformation;
 
namespace Shared
{
[System.Serializable]
    public static class Global
    {
        /// <summary>
        /// ±¾µØ×ÓÍøºÅ
        /// </summary>
        public static readonly byte LocalSubnetID = 252;
        /// <summary>
        /// ±¾µØÉ豸ºÅ
        /// </summary>
        public static readonly byte LocalDeviceID = 252;
        /// <summary>
        /// ±¾µØÉ豸ÀàÐÍ
        /// </summary>
        public static readonly int DeviceType = 0xFFFC;
 
        /// <summary>
        /// »ñÈ¡µ±Ç°wifiµÄIPµØÖ·
        /// </summary>
        /// <returns></returns>
        public static string IpAddress
        {
            get
            {
                foreach (var networkInterface in System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces())
                {
                    foreach (var unicastAddresses in networkInterface.GetIPProperties().UnicastAddresses)
                    {
                        if (unicastAddresses.Address.AddressFamily == AddressFamily.InterNetwork && unicastAddresses.Address.ToString() != "127.0.0.1")
                        {
                            return unicastAddresses.Address.ToString();
                        }
                    }
                }
                return "127.0.0.1";
            }
        }
    }
}