加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

用WebService获取服务端硬件信息和客户端IP,MAC,浏览器信息,所

发布时间:2020-12-17 02:53:33 所属栏目:安全 来源:网络整理
导读:using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Web; using System.Web.Services; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlCo
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Web; using System.Web.Services; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Management; using System.Net; using System.Runtime.InteropServices; using System.IO; namespace CHardwardInfo { ?? ?/// <summary> ?? ?/// Service1 的摘要说明。 ?? ?/// GetHostName() 获取机器名 ?? ?/// GetHostIP() 获取服务器IP ?? ?/// GetHostMac() 获取服务器MAC地址 ?? ?/// GetCustomerIP() 获取客户端动态IP地址 ?? ?/// GetCustomerMacInfo() 获取内部网客户端MAC地址 ?? ?/// GetCustomerBroswer()客户端浏览器信息 ?? ?/// GetCpuId() .获取CPU编号 ?? ?/// GetMainHardDiskId 获取主硬盘编号 ??? ///要引用一个公用? //Webservice:http://www.youthbar.com/IpSearch/GetAddressByIP.asmx ?? ?/// </summary> ?? ?public class Service1 : System.Web.Services.WebService ?? ?{ ?? ??? ?[DllImport("Iphlpapi.dll")] ?? ??? ?private static? extern int SendARP(Int32 dest,Int32 host,ref Int64 mac,ref Int32 length); ?? ??? ?[DllImport("Ws2_32.dll")] ?? ??? ?private static extern Int32 inet_addr(string ip); ?? ??? ?public Service1() ?? ??? ?{ ?? ??? ??? ?//CODEGEN: 该调用是 ASP.NET Web 服务设计器所必需的 ?? ??? ??? ?InitializeComponent(); ?? ??? ?} ?? ??? ?#region 组件设计器生成的代码 ?? ??? ? ??? ??? //Web 服务设计器所必需的 ??? ??? private IContainer components = null; ??? ??? ??? ??? ??? ??? /// <summary> ??? ??? /// 设计器支持所需的方法 - 不要使用代码编辑器修改 ??? ??? /// 此方法的内容。 ??? ??? /// </summary> ??? ??? private void InitializeComponent() ??? ??? { ??? ??? } ??? ??? /// <summary> ??? ??? /// 清理所有正在使用的资源。 ??? ??? /// </summary> ??? ??? protected override void Dispose( bool disposing ) ??? ??? { ??? ??? ??? if(disposing && components != null) ??? ??? ??? { ??? ??? ??? ??? components.Dispose(); ??? ??? ??? } ??? ??? ??? base.Dispose(disposing);??? ??? ??? ??? } ??? ??? ??? ??? #endregion ??? ??? // WEB 服务示例 ??? ??? // HelloWorld() 示例服务返回字符串 Hello World ??? ??? // 若要生成,请取消注释下列行,然后保存并生成项目 ??? ??? // 若要测试此 Web 服务,请按 F5 键 ??? ??? [WebMethod] ??? ??? public string GetHostName() ??? ??? { ??? ??? ??? return System.Net.Dns.GetHostName(); ??? ??? } ??? ??? [WebMethod] ??? ??? public string GetCpuId() ??? ??? { ??? ??? ??? System.Management.ManagementClass mc=new ManagementClass("Win32_Processor"); ??? ??? ??? System.Management.ManagementObjectCollection moc=mc.GetInstances(); ??? ??? ??? string strCpuID=null; ??? ??? ??? foreach(System.Management.ManagementObject mo in moc) ??? ??? ??? { ??? ??? ??? ??? strCpuID=mo.Properties["ProcessorID"].Value.ToString(); ??? ??? ??? ??? break; ??? ??? ??? } ??? ??? ??? return strCpuID; ??? ??? } ??? ??? [WebMethod] ??? ??? public string GetMainHardDiskId() ??? ??? { ??? ??? ??? ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia"); ??? ??? ??? String strHardDiskID = null ; ??? ??? ??? foreach(ManagementObject mo in searcher.Get()) ??? ??? ??? {?? ??? ??? ??? ??? strHardDiskID = mo["SerialNumber"].ToString().Trim(); ??? ??? ??? ??? break;???????? ??? ??? ??? } ??? ??? ??? return strHardDiskID ; ??? ??? } ??? ??? [WebMethod] ??? ??? public string GetHostIP() ??? ??? { ??? ??? ??? string s=""; ??? ??? ??? System.Net.IPAddress[] addressList = Dns.GetHostByName(Dns.GetHostName()).AddressList;? ??? ??? ??? for (int i = 0; i < addressList.Length; i ++) ??? ??? ??? { ??? ??? ??? ??? s += addressList[i].ToString(); ??? ??? ??? } ??? ??? ??? return? s; ??? ??? } ??? ??? [WebMethod] ??? ??? public string GetHostMAC() ??? ??? { ??? ??? ??? string mac=""; ??? ??? ??? System.Management.ManagementClass mc=new ManagementClass("Win32_NetworkAdapterConfiguration"); ??? ??? ??? ManagementObjectCollection moc=mc.GetInstances(); ??? ??? ??? foreach(ManagementObject mo in moc) ??? ??? ??? { ??? ??? ??? ??? if(mo["IPEnabled"].ToString()=="True") ??? ??? ??? ??? ??? mac=mo["MacAddress"].ToString();??? ??? ??? ??? ??? ??? ??? ??? } ??? ??? ??? return mac; ??? ??? } ??? ??? [WebMethod] ??? ??? public string GetCustomerIP() ??? ??? { ??? ??? ??? string CustomerIP=""; ??? ??? ??? if(HttpContext.Current.Request.ServerVariables["HTTP_VIA"]!=null) ??? ??? ??? { ??? ??? ??? ??? CustomerIP=HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString(); ??? ??? ??? } ??? ??? ??? else ??? ??? ??? { ??? ??? ??? ??? CustomerIP=HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString(); ??? ??? ??? } ??? ??? ??? return CustomerIP; ??? ??? ??? ???????????? ??? ??? } ??? ??? [WebMethod] ??? ??? public string GetCustomerBroswer() ??? ??? { ??? ??? ??? ??? ??? ??? return HttpContext.Current.Request.ServerVariables["HTTP_USER_AGENT"].ToString(); ??? ??? } ??? ??? [WebMethod] ??? ??? public string GetCustomerMacInfo(string HostIP,string CustomerIP) ??? ??? { ??? ??? ??? Int32 ldest= inet_addr(CustomerIP);//目的地的ip ??? ??? ??? Int32 lhost= inet_addr(HostIP);//本地的ip ??? ??? ??? Int64 macinfo=new Int64(); ??? ??? ??? Int32 len=6; ??? ??? ??? //int len=macinfo.Length; ??? ??? ??? SendARP(ldest,ref macinfo,ref len); ??? ??? ??? string originalMACAddress = Convert.ToString(macinfo,16); ??? ??? ??? if (originalMACAddress.Length<12) ??? ??? ??? { ??? ??? ??? ??? originalMACAddress = originalMACAddress.PadLeft(12,'0'); ??? ??? ??? } ??? ??? ??? string macAddress; ??? ??? ??? if(originalMACAddress!="0000" && originalMACAddress.Length==12) ??? ??? ??? { ??? ??? ??? ??? string mac1,mac2,mac3,mac4,mac5,mac6; ??? ??? ??? ??? mac1=originalMACAddress.Substring(10,2); ??? ??? ??? ??? mac2=originalMACAddress.Substring(8,2); ??? ??? ??? ??? mac3=originalMACAddress.Substring(6,2); ??? ??? ??? ??? mac4=originalMACAddress.Substring(4,2); ??? ??? ??? ??? mac5=originalMACAddress.Substring(2,2); ??? ??? ??? ??? mac6=originalMACAddress.Substring(0,2); ??? ??? ??? ??? macAddress=mac1+"-"+mac2+"-"+mac3+"-"+mac4+"-"+mac5+"-"+mac6; ??? ??? ??? } ??? ??? ??? else ??? ??? ??? { ??? ??? ??? ??? macAddress=""; ??? ??? ??? } ??? ??? ??? return macAddress.ToUpper(); ??? ??? } ??? ??? [WebMethod] ??? ??? public string GetAddressByIp(string userIP) ??? ??? { ??? ??? ??? getAddress.GetAddressByIP address=new getAddress.GetAddressByIP(); ??? ??? ??? return address.GetAddress(userIP).ToString(); ??? ??? } ??? } } ??

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读