在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
1、获取客户端IP:Request.ServerVariables.Get("Remote_Addr").ToString(); 2、获取客户端主机名:Request.ServerVariables.Get("Remote_Host").ToString(); 3、客户端浏览器:Request.Browser.Browser; 4、客户端浏览器 版本号:Request.Browser.MajorVersion; 5、客户端操作系统:Request.Browser.Platform; 6、获取服务器IP:Request.ServerVariables.Get("Local_Addr").ToString(); 7、获取服务器名:Request.ServerVariables.Get("Server_Name").ToString();
foreach(String o in Request.ServerVariables){ Response.Write(o+"="+Request.ServerVariables[o]+"<br>"); }
string stringMAC = ""; string stringIP = ""; ManagementClass MC = new ManagementClass ("Win32_NetworkAdapterConfiguration"); ManagementObjectCollection MOC= MC.GetInstances(); foreach(ManagementObject MO in MOC) { if ((bool)MO["IPEnabled"] == true) { stringMAC += MO["MACAddress"].ToString(); //获取网卡的地址 string[] IPAddresses = (string[]) MO["IPAddress"]; //获取本地的IP地址 if(IPAddresses.Length > 0) stringIP = IPAddresses[0]; Response.Write(stringMAC+"/"+stringIP); } }
//要引用到以下两个命名空间 using System.Diagnostics; using System.Text.RegularExpressions; //获取远程客户端的网卡物理地址(MAC) public string GetMac(string IP) //para IP is the client's IP { string dirResults=""; ProcessStartInfo psi = new ProcessStartInfo(); Process proc = new Process(); psi.FileName = "nbtstat"; psi.RedirectStandardInput = false; psi.RedirectStandardOutput = true; psi.Arguments = "-A " + IP; psi.UseShellExecute = false; proc = Process.Start(psi); dirResults = proc.StandardOutput.ReadToEnd(); proc.WaitForExit(); dirResults=dirResults.Replace("\r","").Replace("\n","").Replace("\t",""); Regex reg=new Regex("Mac[ ]{0,}Address[ ]{0,}=[ ]{0,}(?<key>((.)*?))__MAC",RegexOptions.IgnoreCase|RegexOptions.Compiled); Match mc=reg.Match(dirResults+"__MAC"); if(mc.Success) { return mc.Groups["key"].Value; } else { reg=new Regex("Host not found",RegexOptions.IgnoreCase|RegexOptions.Compiled); mc=reg.Match(dirResults); if(mc.Success) { return "Host not found!"; } else { return ""; } } } //在页面上打印出客户端的网卡物理地址(MAC) Response.Write(this.GetMac(Request.UserHostAddress.ToString()));
C#
IP
1、获取客户端IP:Request.ServerVariables.Get("Remote_Addr").ToString(); 2、获取客户端主机名:Request.ServerVariables.Get("Remote_Host").ToString(); 3、客户端浏览器:Request.Browser.Browser; 4、客户端浏览器 版本号:Request.Browser.MajorVersion; 5、客户端操作系统:Request.Browser.Platform; 6、获取服务器IP:Request.ServerVariables.Get("Local_Addr").ToString(); 7、获取服务器名:Request.ServerVariables.Get("Server_Name").ToString();
foreach(String o in Request.ServerVariables){ Response.Write(o+"="+Request.ServerVariables[o]+"<br>"); }
string stringMAC = ""; string stringIP = ""; ManagementClass MC = new ManagementClass ("Win32_NetworkAdapterConfiguration"); ManagementObjectCollection MOC= MC.GetInstances(); foreach(ManagementObject MO in MOC) { if ((bool)MO["IPEnabled"] == true) { stringMAC += MO["MACAddress"].ToString(); //获取网卡的地址 string[] IPAddresses = (string[]) MO["IPAddress"]; //获取本地的IP地址 if(IPAddresses.Length > 0) stringIP = IPAddresses[0]; Response.Write(stringMAC+"/"+stringIP); } }
//要引用到以下两个命名空间 using System.Diagnostics; using System.Text.RegularExpressions; //获取远程客户端的网卡物理地址(MAC) public string GetMac(string IP) //para IP is the client's IP { string dirResults=""; ProcessStartInfo psi = new ProcessStartInfo(); Process proc = new Process(); psi.FileName = "nbtstat"; psi.RedirectStandardInput = false; psi.RedirectStandardOutput = true; psi.Arguments = "-A " + IP; psi.UseShellExecute = false; proc = Process.Start(psi); dirResults = proc.StandardOutput.ReadToEnd(); proc.WaitForExit(); dirResults=dirResults.Replace("\r","").Replace("\n","").Replace("\t",""); Regex reg=new Regex("Mac[ ]{0,}Address[ ]{0,}=[ ]{0,}(?<key>((.)*?))__MAC",RegexOptions.IgnoreCase|RegexOptions.Compiled); Match mc=reg.Match(dirResults+"__MAC"); if(mc.Success) { return mc.Groups["key"].Value; } else { reg=new Regex("Host not found",RegexOptions.IgnoreCase|RegexOptions.Compiled); mc=reg.Match(dirResults); if(mc.Success) { return "Host not found!"; } else { return ""; } } } //在页面上打印出客户端的网卡物理地址(MAC) Response.Write(this.GetMac(Request.UserHostAddress.ToString()));
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论