在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Management; using System.Management.Instrumentation; using System.Net; namespace TaoBaoShuaId { class TaoBaoShuaClass { #region 获得客户端外网IP地址 /// <summary> /// 获得客户端外网IP地址 /// </summary> /// <returns>IP地址</returns> public string getClientInternetIPAddress() { string internetAddress = ""; try { using (WebClient webClient = new WebClient()) { internetAddress = webClient.DownloadString("http://www.coridc.com/ip");//从外部网页获得IP地址 //判断IP是否合法 if (!System.Text.RegularExpressions.Regex.IsMatch(internetAddress, "[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}")) { internetAddress = webClient.DownloadString("http://fw.qq.com/ipaddress");//从腾讯提供的API中获得IP地址 } } //返回外网IP地址 return internetAddress; } catch { return "外网IP地址:unknown"; } finally { } } #endregion #region 获取Mac /// <summary> /// 获取Mac /// </summary> /// <returns></returns> public string getMac() { string MacAddr = null; ManagementObjectSearcher Query = new ManagementObjectSearcher("select * from Win32_NetworkAdapterConfiguration"); ManagementObjectCollection QueryCollection = Query.Get(); foreach (ManagementObject mo in QueryCollection) { if (mo["IPEnabled"].ToString() == "True") MacAddr = mo["MacAddress"].ToString(); } return MacAddr; } #endregion } } |
请发表评论