| | |
| | | using System.Collections; |
| | | using System.Collections.Generic; |
| | | using UnityEngine; |
| | | using System.Net.NetworkInformation; |
| | | using System; |
| | | using System.Net; |
| | | using System.Net.Sockets; |
| | | using System.IO; |
| | | using System.Text.RegularExpressions; |
| | | using Cysharp.Threading.Tasks; |
| | | using UnityEngine.Networking; |
| | | |
| | | #if !UNITY_WEBGL |
| | | using System.Net.NetworkInformation; |
| | | using System.Net; |
| | | using System.IO; |
| | | #endif |
| | | |
| | | #if UNITY_IOS |
| | | using UnityEngine.iOS; |
| | |
| | | static string mac = string.Empty; |
| | | public static string GetMac() |
| | | { |
| | | #if !UNITY_WEBGL |
| | | if (string.IsNullOrEmpty(mac)) |
| | | { |
| | | try |
| | |
| | | Debug.Log(ex); |
| | | } |
| | | } |
| | | |
| | | #endif |
| | | return mac; |
| | | } |
| | | |
| | | static string ipPattern = "[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}"; |
| | | static string ip = string.Empty; |
| | | public static string GetCachedIp() => ip; |
| | | public static async UniTask<string> GetIp() |
| | | { |
| | | try |
| | |
| | | if (string.IsNullOrEmpty(ip)) |
| | | { |
| | | string url = "http://pv.sohu.com/cityjson"; |
| | | WebRequest wRequest = WebRequest.Create(url); |
| | | wRequest.Method = "GET"; |
| | | wRequest.ContentType = "text/html;charset=UTF-8"; |
| | | WebResponse wResponse = await wRequest.GetResponseAsync(); |
| | | Stream stream = wResponse.GetResponseStream(); |
| | | StreamReader reader = new StreamReader(stream, System.Text.Encoding.Default); |
| | | string str = await reader.ReadToEndAsync(); |
| | | |
| | | reader.Close(); |
| | | wResponse.Close(); |
| | | |
| | | var match = Regex.Match(str, ipPattern); |
| | | if (match != null) |
| | | using (var request = UnityWebRequest.Get(url)) |
| | | { |
| | | ip = match.Value; |
| | | await request.SendWebRequest(); |
| | | if (request.result == UnityWebRequest.Result.Success) |
| | | { |
| | | string str = request.downloadHandler.text; |
| | | var match = Regex.Match(str, ipPattern); |
| | | if (match != null) |
| | | { |
| | | ip = match.Value; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |