using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Management; using System.Net; using System.Net.NetworkInformation; using System.Net.Sockets; using System.Text; using System.Text.RegularExpressions; namespace AIMSExtension { public static class GPFunctions { public static int CInt(T t) { int result = 0; try { result = Convert.ToInt32(t); } catch (Exception) { result = 0; } return result; } public static int IntParse(T t) { bool flag = t == null; int result; if (flag) { result = 0; } else { result = GPFunctions.IntParse(t.ToString()); } return result; } public static int IntParse(string strnum) { strnum = strnum.Trim(); bool flag = strnum == null || strnum.Length == 0; int result; if (flag) { result = 0; } else { int length = strnum.Length; int num = length; for (int i = 0; i < length; i++) { string text = strnum.Substring(i, 1); bool flag2 = text.CompareTo("0") < 0 || text.CompareTo("9") > 0; if (flag2) { num = i; break; } } bool flag3 = num == 0; if (flag3) { result = 0; } else { result = Convert.ToInt32(strnum.Substring(0, num)); } } return result; } public static bool CBool(string val) { bool flag = val == null; bool result; if (flag) { result = false; } else { val = val.Trim().ToLower(); bool flag2 = val == "true" || val == "false"; if (flag2) { result = bool.Parse(val); } else { bool flag3 = GPFunctions.CDecimal(val).CompareTo(decimal.Zero) == 0; result = !flag3; } } return result; } public static bool CBool(T t) { bool flag = t == null; return !flag && GPFunctions.CBool(t.ToString()); } public static long CLng(T t) { long result = 0L; try { result = Convert.ToInt64(t); } catch (Exception) { result = 0L; } return result; } public static decimal CDecimal(T t) { decimal result = 0m; try { result = Convert.ToDecimal(t); } catch (Exception) { result = 0m; } return result; } public static double CDbl(T t) { double num = 0.0; try { num = Convert.ToDouble(t); bool flag = num != 0.0; if (flag) { bool flag2 = num > 0.0; if (flag2) { num = Math.Round(num + 1E-08, 6); } else { num = Math.Round(num - 1E-08, 6); } } } catch (Exception) { num = 0.0; } return num; } public static DateTime CDate(T t) { DateTime result = new DateTime(1, 1, 1); try { result = Convert.ToDateTime(t); } catch (Exception) { } return result; } public static DateTime CDate2(string yyyyMMddHHmmss) { int length = yyyyMMddHHmmss.Length; bool flag = length < 8; DateTime result; if (flag) { result = new DateTime(1, 1, 1); } else { int hour = 0; int minute = 0; int second = 0; int year = Convert.ToInt32(yyyyMMddHHmmss.Substring(0, 4)); int month = Convert.ToInt32(yyyyMMddHHmmss.Substring(4, 2)); int day = Convert.ToInt32(yyyyMMddHHmmss.Substring(6, 2)); bool flag2 = length == 8; if (flag2) { result = new DateTime(year, month, day); } else { bool flag3 = length >= 10; if (flag3) { hour = Convert.ToInt32(yyyyMMddHHmmss.Substring(8, 2)); } bool flag4 = length >= 12; if (flag4) { minute = Convert.ToInt32(yyyyMMddHHmmss.Substring(10, 2)); } bool flag5 = length >= 14; if (flag5) { second = Convert.ToInt32(yyyyMMddHHmmss.Substring(12, 2)); } result = new DateTime(year, month, day, hour, minute, second); } } return result; } public static string CStr(T t) { bool flag = t == null; string result; if (flag) { result = ""; } else { result = t.ToString(); } return result; } public static string CStr(T t, int len) { string text = GPFunctions.CStr(t); return (len > text.Length) ? text : text.Substring(0, len); } public static string CStrEx(T t) { string text = GPFunctions.CStr(t); bool flag = string.IsNullOrWhiteSpace(text); string result; if (flag) { result = ""; } else { result = Regex.Replace(text, "^\\s+|\\s+$", ""); } return result; } public static string CStrEx(T t, int len) { string text = GPFunctions.CStr(t); bool flag = string.IsNullOrWhiteSpace(text); string result; if (flag) { result = ""; } else { text = Regex.Replace(text, "^\\s+|\\s+$", ""); result = ((len > text.Length) ? text : text.Substring(0, len)); } return result; } public static int GetNvarcharLength(string str) { bool flag = string.IsNullOrWhiteSpace(str); int result; if (flag) { result = 0; } else { byte[] bytes = Encoding.Default.GetBytes(str); result = bytes.Length; } return result; } public static string GetVarcharLengthStr(string str, int len) { bool flag = string.IsNullOrWhiteSpace(str); string result; if (flag) { result = ""; } else { byte[] bytes = Encoding.Default.GetBytes(str); int num = bytes.Length; bool flag2 = num <= len; if (flag2) { result = str; } else { bool flag3 = bytes[len - 1] <= 127; if (flag3) { result = Encoding.Default.GetString(bytes, 0, len); } else { result = Encoding.Default.GetString(bytes, 0, len - 1); } } } return result; } public static string Trim(string strnum) { string text = strnum.Trim(); bool flag = string.IsNullOrWhiteSpace(strnum); string result; if (flag) { result = ""; } else { result = Regex.Replace(strnum, "^\\s+|\\s+$", ""); } return result; } public static bool IsMail(string fmail) { Regex regex = new Regex("^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$"); return regex.IsMatch(fmail); } public static bool IsIPv4Adress(string ipstr) { int[] array = GPFunctions.StringToIntArray(ipstr, '.'); bool flag = array.Length != 4; bool result; if (flag) { result = false; } else { for (int i = 0; i < 4; i++) { int num = array[i]; bool flag2 = i == 0; if (flag2) { bool flag3 = num < 1 || num > 255; if (flag3) { result = false; return result; } } else { bool flag4 = num < 0 || num > 255; if (flag4) { result = false; return result; } } } result = true; } return result; } public static bool IsMobile(string mobile) { Regex regex = new Regex("[1-9]\\d{10}"); return regex.IsMatch(mobile); } public static bool IsMobile(long mobile) { return mobile >= 10000000000L && mobile <= 99999999999L; } public static bool IsAllNumber(string inStr) { string text = GPFunctions.CStrEx(inStr); int length = text.Length; bool flag = length == 0; bool result; if (flag) { result = false; } else { for (int i = 0; i < length; i++) { char c = text[i]; bool flag2 = c != '.' && (c < '0' || c > '9'); if (flag2) { result = false; return result; } } result = true; } return result; } public static bool IsAscIIString(string input) { bool flag = true; bool flag2 = string.IsNullOrWhiteSpace(input); bool result; if (flag2) { result = true; } else { int length = input.Length; for (int i = 0; i < length; i++) { char value = input[i]; bool flag3 = Convert.ToByte(value) > 127; if (flag3) { flag = false; break; } } result = flag; } return result; } public static bool IsVariableString(string input) { Regex regex = new Regex("^[_a-zA-Z]\\w*$"); bool flag = string.IsNullOrWhiteSpace(input); return !flag && regex.IsMatch(input); } public static string SqlDateStr(DateTime d) { bool flag = d.Year <= 1; string result; if (flag) { result = "NULL"; } else { result = string.Format("'{0}'", GPFunctions.DateTimeStr(d)); } return result; } public static string SqlDateStr(object dateObj) { bool flag = dateObj == DBNull.Value; string result; if (flag) { result = "NULL"; } else { bool flag2 = dateObj.GetType().Name == "DateTime"; if (flag2) { DateTime d = Convert.ToDateTime(dateObj); result = GPFunctions.SqlDateStr(d); } else { string text = "NULL"; DateTime d; bool flag3 = DateTime.TryParse(dateObj.ToString(), out d); if (flag3) { text = GPFunctions.SqlDateStr(d); } result = text; } } return result; } public static string DateStr(DateTime d) { return d.ToString("yyyy/MM/dd"); } public static string DateTimeStr(DateTime d) { bool flag = d.Hour + d.Minute + d.Second == 0; string result; if (flag) { result = d.ToString("yyyy/MM/dd"); } else { result = d.ToString("yyyy/MM/dd HH:mm:ss"); } return result; } public static string Now() { return DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); } public static string Today() { return DateTime.Now.Date.ToString("yyyy/MM/dd"); } public static int GetTimeStamp(DateTime d) { return Convert.ToInt32(d.Subtract(DateTime.Parse("1970/1/1")).TotalSeconds); } public static int GetUnixTimeStamp(DateTime d) { return Convert.ToInt32(d.Subtract(DateTime.Parse("1970/1/1 8:0:0")).TotalSeconds); } public static string BigIntToTimestamp(long i64) { string text = i64.ToString("X2"); int length = text.Length; return "0x0000000000000000".Substring(0, 18 - length) + text; } public static DateTime IntToTime(int totalSeconds) { return DateTime.Parse("1970/1/1").AddSeconds((double)(totalSeconds + 86400)); } public static long TimeOf() { return GPFunctions.TimeOf(DateTime.Now); } public static long TimeOf(DateTime t) { DateTime d = new DateTime(1970, 1, 1); return (long)(t - d).TotalSeconds; } public static DateTime OracleTime() { DateTime now = DateTime.Now; return new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second); } public static DateTime OracleTime(DateTime d) { return new DateTime(d.Year, d.Month, d.Day, d.Hour, d.Minute, d.Second); } public static Dictionary StringToDict(string str, string rowdeli, string coldeli) { string text = str.Trim(); string[] array = Regex.Split(str, rowdeli); int num = array.Length; Dictionary dictionary = new Dictionary(StringComparer.OrdinalIgnoreCase); for (int i = 0; i < num; i++) { string[] array2 = Regex.Split(array[i], coldeli); bool flag = array2.Length > 1; if (flag) { string text2 = array2[0].Trim(); bool flag2 = text2.Length > 0; if (flag2) { dictionary[text2] = array2[1].Trim(); } } } return dictionary; } public static Dictionary StringToDict(string str, char rowdeli, char coldeli) { string text = str.Trim(); string[] array = text.Split(new char[] { rowdeli }); int num = array.Length; Dictionary dictionary = new Dictionary(StringComparer.OrdinalIgnoreCase); for (int i = 0; i < num; i++) { string[] array2 = array[i].Split(new char[] { coldeli }); bool flag = array2.Length > 1; if (flag) { string text2 = array2[0].Trim(); bool flag2 = text2.Length > 0; if (flag2) { dictionary[text2] = array2[1].Trim(); } } } return dictionary; } public static Dictionary StringToDictInt(string str, char rowdeli, char coldeli) { string text = str.Trim(); string[] array = text.Split(new char[] { rowdeli }); int num = array.Length; Dictionary dictionary = new Dictionary(StringComparer.OrdinalIgnoreCase); for (int i = 0; i < num; i++) { string[] array2 = array[i].Split(new char[] { coldeli }); bool flag = array2.Length > 1; if (flag) { string text2 = array2[0].Trim(); bool flag2 = text2.Length > 0; if (flag2) { dictionary[text2] = GPFunctions.CInt(array2[1].Trim()); } } } return dictionary; } public static string DictionaryToString(Dictionary dic, string rowdeli, string coldeli) { int num = dic.Count; string[] array = new string[num]; num = 0; foreach (KeyValuePair current in dic) { string[] arg_57_0 = array; int expr_26 = num++; string arg_52_0 = "{0}{1}{2}"; object arg_52_1 = current.Key; TValue value = current.Value; arg_57_0[expr_26] = string.Format(arg_52_0, arg_52_1, coldeli, value.ToString()); } return string.Join(rowdeli, array); } public static string DictionaryToString(IDictionary dic, string rowdeli, string coldeli) { int num = dic.Count; string[] array = new string[num]; num = 0; foreach (DictionaryEntry dictionaryEntry in dic) { bool flag = dictionaryEntry.Value.GetType().Name.IndexOf("Dictionary") >= 0; if (flag) { Type[] genericArguments = dictionaryEntry.Value.GetType().GetGenericArguments(); bool flag2 = genericArguments.Length == 2; if (flag2) { string arg = GPFunctions.DictionaryToString((IDictionary)dictionaryEntry.Value, rowdeli, coldeli); array[num++] = string.Format("{0}{1}{{{2}}}", dictionaryEntry.Key, coldeli, arg); } } else { array[num++] = string.Format("{0}{1}{2}", dictionaryEntry.Key, coldeli, dictionaryEntry.Value.ToString()); } } return string.Join(rowdeli, array); } public static string SortedKeyValue(string str, char colchar, char rowchar) { SortedDictionary sortedDictionary = new SortedDictionary(); string[] array = str.Split(new char[] { rowchar }); string[] array2 = array; for (int i = 0; i < array2.Length; i++) { string text = array2[i]; bool flag = text.Length > 0; if (flag) { string[] array3 = text.Split(new char[] { colchar }); bool flag2 = array3.Length == 2; if (flag2) { string text2 = array3[0].Trim(); bool flag3 = text2.Length > 0; if (flag3) { sortedDictionary[text2] = array3[1]; } } } } return GPFunctions.SortedKeyValue(sortedDictionary, colchar, rowchar); } public static string SortedKeyValue(SortedDictionary d, char colchar, char rowchar) { StringBuilder stringBuilder = new StringBuilder(); int num = 0; string value = (rowchar == '\0') ? "" : rowchar.ToString(); foreach (KeyValuePair current in d) { bool flag = num > 0; if (flag) { stringBuilder.Append(value); } else { num++; } stringBuilder.Append(current.Key + colchar.ToString() + current.Value); } return stringBuilder.ToString(); } public static string SortedKeyValue(Dictionary d, char colchar, char rowchar) { SortedDictionary sortedDictionary = new SortedDictionary(); foreach (KeyValuePair current in d) { sortedDictionary.Add(current.Key, current.Value); } return GPFunctions.SortedKeyValue(sortedDictionary, colchar, rowchar); } public static string Random(int n) { StringBuilder stringBuilder = new StringBuilder(); int seed = Convert.ToInt32((DateTime.Now - new DateTime(0L)).TotalMilliseconds); Random random = new Random(seed); string text = "1234567890ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz!@$%^&*()-_=+[]{}|\\;:’”,.<>?/`~"; for (int i = 0; i < n; i++) { int index = random.Next(90); stringBuilder.Append(text[index]); } return stringBuilder.ToString(); } public static string RandomInt(int n) { int seed = Convert.ToInt32((DateTime.Now - new DateTime(0L)).TotalMilliseconds); Random random = new Random(seed); int num = (int)Math.Pow(10.0, (double)n) - 1; string text = random.Next(num).ToString(); num = text.Length; bool flag = num == n; string result; if (flag) { result = text; } else { result = "00000".Substring(0, n - num) + text; } return result; } public static string SqlEncode(string s) { return s.Replace("'", "''"); } public static string JsonString(string keyval) { return "\"" + keyval + "\""; } public static string EncodeJsonValue(string s) { bool flag = s == null || s == ""; string result; if (flag) { result = ""; } else { result = s.Replace("\"", "\\\"").Replace(Convert.ToString('\r'), "\\r").Replace(Convert.ToString('\n'), "\\n"); } return result; } public static string HtmlDecode(string s) { return s.Replace("&", "&").Replace("<", "<").Replace(">", ">").Replace(" ", " ").Replace("'", "'").Replace(""", "\""); } public static string RepeatString(string s, int num) { StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < num; i++) { stringBuilder.Append(s); } return stringBuilder.ToString(); } public static int[] StringToIntArray(string ints) { return GPFunctions.StringToIntArray(ints, ','); } public static int[] StringToIntArray(string ints, char delimeter) { return GPFunctions.StringToListInt(ints, delimeter).ToArray(); } public static string[] StringToStringArray(string strs) { return GPFunctions.StringToStringArray(strs, ','); } public static string[] StringToStringArray(string strs, char delimeter) { return GPFunctions.StringToListString(strs, delimeter).ToArray(); } public static List StringToListString(string strs, char delimeter) { List list = new List(); string[] array = strs.Split(new char[] { delimeter }); int i = 0; int num = array.Length; while (i < num) { string text = array[i].Trim(); bool flag = text.Length > 0; if (flag) { list.Add(text); } i++; } return list; } public static List StringToListInt(string ints, char delimeter) { List list = new List(); string[] array = ints.Split(new char[] { delimeter }); int i = 0; int num = array.Length; while (i < num) { string text = array[i].Trim(); bool flag = text.Length > 0; if (flag) { list.Add(Convert.ToInt32(text)); } i++; } return list; } public static string InSQLStringInt(string idsstr, char deli) { string a = idsstr.Replace(" ", ""); bool flag = a == ""; if (flag) { throw new Exception(string.Format("Invalid Parameter(idsstr={0})。", idsstr)); } string[] array = idsstr.Split(new char[] { deli }); Dictionary dictionary = new Dictionary(); int i = 0; int num = array.Length; while (i < num) { int key = GPFunctions.CInt(array[i]); dictionary[key] = 1; i++; } return string.Join(",", dictionary.Keys); } public static string InSQLStringDecimal(string idsstr, char deli) { string a = idsstr.Replace(" ", ""); bool flag = a == ""; if (flag) { throw new Exception(string.Format("Invalid Parameter(idsstr={0})。", idsstr)); } string[] array = idsstr.Split(new char[] { deli }); Dictionary dictionary = new Dictionary(); decimal value = 0m; int i = 0; int num = array.Length; while (i < num) { value = GPFunctions.CDecimal(array[i]); dictionary[value.ToString()] = value; i++; } return string.Join(",", dictionary.Keys); } public static string GetIdsTable(string ids) { string[] idarr = ids.Split(new char[] { ',' }); return GPFunctions.GetIdsTable(idarr); } public static string GetIdsTable(string ids, char deli) { string[] idarr = ids.Split(new char[] { deli }); return GPFunctions.GetIdsTable(idarr); } public static string GetIdsTable(string[] idarr) { StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < idarr.Length; i++) { bool flag = i > 0; if (flag) { stringBuilder.Append(" UNION "); } stringBuilder.Append(string.Format("SELECT {0} as xh, {1} as id", i, idarr[i])); } return stringBuilder.ToString(); } public static byte[] HexStringToBytes(string hexstr) { hexstr = hexstr.Trim(); int num = hexstr.Length; bool flag = num % 2 != 0; if (flag) { hexstr += " "; num++; } int num2 = num / 2; byte[] array = new byte[num2]; for (int i = 0; i < num2; i++) { string value = hexstr.Substring(i * 2, 2); array[i] = Convert.ToByte(Convert.ToInt16(value, 16)); } return array; } public static byte[] HexStringToBytes(string hexstr, char seperator) { string[] array = hexstr.Trim().Split(new char[] { seperator }); int num = array.Length; byte[] array2 = new byte[num]; for (int i = 0; i < num; i++) { string value = array[i]; array2[i] = Convert.ToByte(Convert.ToInt32(value, 16)); } return array2; } public static int BytesIndexOf(byte[] source, int startPos, byte[] pattern) { int num = source.Length; int num2 = pattern.Length; bool flag = num < num2; int result; if (flag) { result = -1; } else { bool flag2 = num2 == 1; if (flag2) { byte b = pattern[0]; for (int i = startPos; i < num; i++) { bool flag3 = source[i] == b; if (flag3) { result = i; return result; } } result = -1; } else { for (int j = startPos; j < num - num2 + 1; j++) { for (int k = 0; k < num2; k++) { bool flag4 = source[j + k] != pattern[k]; if (flag4) { break; } bool flag5 = k == num2 - 1; if (flag5) { result = j; return result; } } } result = -1; } } return result; } public static int BytesIndexOf(List source, int startPos, byte[] pattern) { int count = source.Count; int num = pattern.Length; bool flag = count < num; int result; if (flag) { result = -1; } else { bool flag2 = num == 1; if (flag2) { byte b = pattern[0]; for (int i = startPos; i < count; i++) { bool flag3 = source[i] == b; if (flag3) { result = i; return result; } } result = -1; } else { for (int j = startPos; j < count - num + 1; j++) { for (int k = 0; k < num; k++) { bool flag4 = source[j + k] != pattern[k]; if (flag4) { break; } bool flag5 = k == num - 1; if (flag5) { result = j; return result; } } } result = -1; } } return result; } public static string BytesToDecimalString(byte[] bits, char deli = ' ') { int num = bits.Length; StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < num; i++) { bool flag = i == 0; if (flag) { stringBuilder.Append(bits[i].ToString().PadLeft(3)); } else { stringBuilder.Append(string.Format("{0}{1}", deli, bits[i].ToString().PadLeft(3))); } } return stringBuilder.ToString(); } public static string BytesToHexString(byte[] bits) { int num = bits.Length; StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < num; i++) { stringBuilder.Append(bits[i].ToString("x2")); } return stringBuilder.ToString(); } public static string BytesToHexString(byte[] bits, int length) { int num = bits.Length; bool flag = num > length; if (flag) { num = length; } StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < num; i++) { stringBuilder.Append(bits[i].ToString("x2")); } return stringBuilder.ToString(); } public static string BytesToHexString(byte[] bits, char seperator) { return GPFunctions.BytesToHexString(bits, seperator, bits.Length); } public static string BytesToHexString(byte[] bits, char seperator, int length) { int num = bits.Length; bool flag = num > length; if (flag) { num = length; } StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < num; i++) { bool flag2 = i == 0; if (flag2) { stringBuilder.Append(bits[i].ToString("X2")); } else { stringBuilder.Append(seperator.ToString() + bits[i].ToString("X2")); } } return stringBuilder.ToString(); } public static string StringToHexString(string s, string charset) { Encoding encoding = Encoding.GetEncoding(charset); byte[] bytes = encoding.GetBytes(s); return GPFunctions.BytesToHexString(bytes); } public static string StringToHexString(string s, Encoding encode) { byte[] bytes = encode.GetBytes(s); return GPFunctions.BytesToHexString(bytes); } public static string HexStringToString(string hex, Encoding encode) { bool flag = hex == null; string result; if (flag) { result = ""; } else { bool flag2 = hex.Length == 0; if (flag2) { result = ""; } else { byte[] bytes = GPFunctions.HexStringToBytes(hex); result = encode.GetString(bytes); } } return result; } public static string HexStringToString(string hex, string charset) { bool flag = hex == null; string result; if (flag) { result = ""; } else { bool flag2 = hex.Length == 0; if (flag2) { result = ""; } else { byte[] bytes = GPFunctions.HexStringToBytes(hex); Encoding encoding = Encoding.GetEncoding(charset); result = encoding.GetString(bytes); } } return result; } public static string ConvertCodeString(string tbdstr, string charset1, string charset2) { bool flag = tbdstr == null; string result; if (flag) { result = ""; } else { bool flag2 = tbdstr.Length == 0; if (flag2) { result = ""; } else { Encoding encoding = Encoding.GetEncoding(charset1); Encoding encoding2 = Encoding.GetEncoding(charset2); byte[] bytes = encoding.GetBytes(tbdstr); byte[] bytes2 = Encoding.Convert(encoding, encoding2, bytes); string @string = encoding2.GetString(bytes2); result = @string; } } return result; } public static string Utf8ToGBK(string utf8) { Encoding encoding = Encoding.GetEncoding("UTF-8"); Encoding encoding2 = Encoding.GetEncoding("GBK"); byte[] bytes = encoding.GetBytes(utf8); byte[] bits = Encoding.Convert(encoding, encoding2, bytes); return GPFunctions.BytesToHexString(bits, '%'); } public static string GetHostName() { return Dns.GetHostName(); } //public static List GetNetworkAdpaterID() //{ // List list = new List(); // NetworkInterface[] allNetworkInterfaces = NetworkInterface.GetAllNetworkInterfaces(); // NetworkInterface[] array = allNetworkInterfaces; // for (int i = 0; i < array.Length; i++) // { // NetworkInterface networkInterface = array[i]; // MyKeyValue myKeyValue = new MyKeyValue(); // myKeyValue.Key = networkInterface.Name; // string text = networkInterface.GetPhysicalAddress().ToString(); // bool flag = text.Length > 0 && !text.StartsWith("00"); // if (flag) // { // byte[] bits = GPFunctions.HexStringToBytes(text); // text = GPFunctions.BytesToHexString(bits, ':'); // myKeyValue.Value = text.ToUpper(); // list.Add(myKeyValue); // } // } // return list; //} //public static List GetMacAddress() //{ // List list = new List(); // ManagementClass managementClass = new ManagementClass("Win32_NetworkAdapterConfiguration"); // ManagementObjectCollection instances = managementClass.GetInstances(); // using (ManagementObjectCollection.ManagementObjectEnumerator enumerator = instances.GetEnumerator()) // { // while (enumerator.MoveNext()) // { // ManagementObject managementObject = (ManagementObject)enumerator.Current; // bool flag = managementObject["IPEnabled"].ToString() == "True"; // if (flag) // { // string text = managementObject["MacAddress"].ToString(); // bool flag2 = !text.StartsWith("00"); // if (flag2) // { // list.Add(managementObject["MacAddress"].ToString()); // } // } // } // } // bool flag3 = list.Count == 0; // if (flag3) // { // list.Add("98-2C-BC-1C-6B-A5"); // } // return list; //} public static List GetIPAddress() { List list = new List(); IPHostEntry hostEntry = Dns.GetHostEntry(Dns.GetHostName()); IPAddress[] addressList = hostEntry.AddressList; for (int i = 0; i < addressList.Length; i++) { IPAddress iPAddress = addressList[i]; bool flag = iPAddress.AddressFamily == AddressFamily.InterNetwork; if (flag) { list.Add(iPAddress.ToString()); } } bool flag2 = list.Count == 0; if (flag2) { list.Add("127.0.0.1"); } return list; } public static List GetIPAddress(string ipstr) { List list = new List(); IPHostEntry hostEntry = Dns.GetHostEntry(Dns.GetHostName()); IPAddress[] addressList = hostEntry.AddressList; for (int i = 0; i < addressList.Length; i++) { IPAddress iPAddress = addressList[i]; bool flag = iPAddress.AddressFamily == AddressFamily.InterNetwork; if (flag) { string text = iPAddress.ToString(); bool flag2 = text.CompareTo(ipstr) == 0; if (flag2) { list.Clear(); list.Add(text); break; } list.Add(text); } } bool flag3 = list.Count == 0; if (flag3) { list.Add("127.0.0.1"); } return list; } public static List GetIPAddress(string ipstr, string excludedIP) { List list = new List(); IPHostEntry hostEntry = Dns.GetHostEntry(Dns.GetHostName()); IPAddress[] addressList = hostEntry.AddressList; for (int i = 0; i < addressList.Length; i++) { IPAddress iPAddress = addressList[i]; bool flag = iPAddress.AddressFamily == AddressFamily.InterNetwork; if (flag) { string text = iPAddress.ToString(); bool flag2 = ipstr.Length > 0 && text.CompareTo(ipstr) == 0; if (flag2) { list.Clear(); list.Add(text); break; } bool flag3 = !text.StartsWith(excludedIP); if (flag3) { list.Add(text); } } } bool flag4 = list.Count == 0; if (flag4) { list.Add("127.0.0.1"); } return list; } public static uint IPToUInt32(string ip) { string[] array = ip.Split(new char[] { '.' }); bool flag = array.Length != 4; uint result; if (flag) { result = 0u; } else { byte[] array2 = new byte[4]; for (int i = 0; i < 4; i++) { array2[3 - i] = Convert.ToByte(array[i]); } result = BitConverter.ToUInt32(array2, 0); } return result; } public static string GetCMDResult(string cmd, string parameters) { Process process = null; string result = string.Empty; try { process = Process.Start(new ProcessStartInfo(cmd, parameters) { CreateNoWindow = true, UseShellExecute = false, RedirectStandardOutput = true }); result = process.StandardOutput.ReadToEnd(); } catch (Exception ex) { throw new Exception(string.Format("GetCMDResult '{0} {1}' Exception: {2}", cmd, parameters, ex.Message)); } finally { bool flag = process != null; if (flag) { process.Close(); } } return result; } public static List GetMyIPMacInfo(string infos = "") { List list = new List(); bool flag = string.IsNullOrEmpty(infos); if (flag) { infos = GPFunctions.GetCMDResult("ipconfig", "-all"); } string[] array = infos.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); string text = ""; string text2 = ""; string text3 = ""; string text4 = ""; string[] array2 = array; int i = 0; while (i < array2.Length) { string text5 = array2[i]; bool flag2 = text5.Contains(". :"); if (flag2) { string[] array3 = text5.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries); string text6 = array3[1].Trim(); bool flag3 = text6.Length == 0; if (!flag3) { text6 = array3[0].Trim(new char[] { ' ', '.' }); bool flag4 = text6.Contains("IPv4"); if (flag4) { text6 = GPFunctions.ReadNumberString(array3[1]); bool flag5 = GPFunctions.IsIPv4Adress(text6); if (flag5) { text2 = text6; } } else { bool flag6 = text6.StartsWith("物理地址"); if (flag6) { text3 = array3[1].Trim(); } else { bool flag7 = text6.StartsWith("Physical"); if (flag7) { text3 = array3[1].Trim(); } else { bool flag8 = text6.StartsWith("描述"); if (flag8) { text4 = array3[1].Trim(); } else { bool flag9 = text6.StartsWith("Description "); if (flag9) { text4 = array3[1].Trim(); } } } } } } } else { bool flag10 = !text5.StartsWith(" ") && text5.EndsWith(":"); if (flag10) { int num = text5.IndexOf(" "); bool flag11 = num > 0; if (flag11) { bool flag12 = text.Length > 0 && text3.Length > 0 && text4.Length > 0 && text2.Length > 0; if (flag12) { list.Add(new string[] { text, text4, text3, text2 }); } text = text5.Substring(num).Trim(new char[] { ':', ' ' }); text2 = ""; text3 = ""; text4 = ""; } } } i++; continue; } bool flag13 = text.Length > 0 && text3.Length > 0 && text4.Length > 0 && text2.Length > 0; if (flag13) { list.Add(new string[] { text, text4, text3, text2 }); } return list; } public static string ReadNumberString(string strnum) { strnum = strnum.Trim(); bool flag = strnum == null || strnum.Length == 0; string result; if (flag) { result = ""; } else { List list = new List(); int length = strnum.Length; for (int i = 0; i < length; i++) { char c = strnum[i]; bool flag2 = c == '.' || (c >= '0' && c <= '9'); if (!flag2) { break; } list.Add(c); } result = string.Join("", list); } return result; } } }