public static string GetMac() { try { string userHostAddress = HttpContext.Current.Request.UserHostAddress; string ip = HttpContext.Current.Request.UserHostAddress.ToString().Trim(); int dest = IPHelp.inet_addr(ip); IPHelp.inet_addr(ip); long mac = 0; int length = 6; IPHelp.SendARP(dest, 0, ref mac, ref length); string str1 = mac.ToString("X"); if (str1 == "0") { return("错误"); } while (str1.Length < 12) { str1 = str1.Insert(0, "0"); } string str2 = ""; for (int startIndex = 0; startIndex < 11; ++startIndex) { if (startIndex % 2 == 0) { str2 = startIndex != 10 ? "-" + str2.Insert(0, str1.Substring(startIndex, 2)) : str2.Insert(0, str1.Substring(startIndex, 2)); } } return(str2); } catch (Exception ex) { return(ex.ToString()); } }
public static string GetNetIP() { string str = ""; try { Stream responseStream = WebRequest.Create("http://city.ip138.com/ip2city.asp").GetResponse().GetResponseStream(); StreamReader streamReader = new StreamReader(responseStream, Encoding.GetEncoding("gb2312")); string end = streamReader.ReadToEnd(); int startIndex = end.IndexOf("[") + 1; int num = end.IndexOf("]", startIndex); str = end.Substring(startIndex, num - startIndex); streamReader.Close(); responseStream.Close(); } catch { if (Dns.GetHostEntry(Dns.GetHostName()).AddressList.Length > 1) { str = Dns.GetHostEntry(Dns.GetHostName()).AddressList[1].ToString(); } if (string.IsNullOrEmpty(str)) { return(IPHelp.GetIP()); } } return(str); }
public static string GetNetIP() { string text = ""; try { WebRequest webRequest = WebRequest.Create("http://city.ip138.com/ip2city.asp"); Stream responseStream = webRequest.GetResponse().GetResponseStream(); StreamReader streamReader = new StreamReader(responseStream, Encoding.GetEncoding("gb2312")); string text2 = streamReader.ReadToEnd(); int num = text2.IndexOf("[") + 1; int num2 = text2.IndexOf("]", num); text = text2.Substring(num, num2 - num); streamReader.Close(); responseStream.Close(); } catch { if (Dns.GetHostEntry(Dns.GetHostName()).AddressList.Length > 1) { text = Dns.GetHostEntry(Dns.GetHostName()).AddressList[1].ToString(); } if (string.IsNullOrEmpty(text)) { return(IPHelp.GetIP()); } } return(text); }
public static string GetMac() { string result = ""; try { string arg_15_0 = HttpContext.Current.Request.UserHostAddress; string ip = HttpContext.Current.Request.UserHostAddress.ToString().Trim(); int dest = IPHelp.inet_addr(ip); IPHelp.inet_addr(ip); long num = 0L; int num2 = 6; IPHelp.SendARP(dest, 0, ref num, ref num2); string text = num.ToString("X"); if (text == "0") { return("错误"); } while (text.Length < 12) { text = text.Insert(0, "0"); } string text2 = ""; for (int i = 0; i < 11; i++) { if (i % 2 == 0) { if (i == 10) { text2 = text2.Insert(0, text.Substring(i, 2)); } else { text2 = "-" + text2.Insert(0, text.Substring(i, 2)); } } } result = text2; } catch (Exception ex) { result = ex.ToString(); } return(result); }