本文介绍了检索客户端的计算机名称和IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

确实有一个网站,用户正在通过登录进入该网站.现在,我喜欢收集用户的MachineName和IP地址.

我采用了几种方法,但是所有这些方法都将服务器信息而不是代理服务器信息而不是客户端的计算机信息都提供给我.

如果你们中的任何一个人请我提供可能的解决方案,我将不胜感激.

我尝试过的代码段是:

Hi Everybody,

Actually there is a website and users are entering into that site by logging in. Now, I like collect the user''s MachineName and IP address.

I applied several ways but those all give me back the Server''s information rather Proxy Server''s Info, not the Client''s machine info.

I would be highly appreciated if any one of you kindly revert me back with the possible solutions.

The Code snippets Those I tried upon are:

string strDNS = Dns.GetHostName();
string aa = System.Security.Principal.WindowsIdentity.GetCurrent().User.ToString().Trim();
string bb = System.Security.Principal.WindowsIdentity.GetCurrent().Name.Substring(5).ToString().Trim();

//Retrieving Server IPAddress                    
string strHostName = System.Net.Dns.GetHostName();
string strHostIPAddress = System.Net.Dns.GetHostAddresses(System.Net.Dns.GetHostName()).GetValue(0).ToString();

string a = System.Net.Dns.GetHostEntry(Request.ServerVariables["remote_addr"]).HostName;
string b = this.Page.Request.ServerVariables["REMOTE_ADDR"];
string c = Request.UserHostAddress;
string d = Server.HtmlEncode(Request.UserHostName);

//Get The User Ip Address
string ipAddress = GetUserIPAddress();
string str = Request.Form["hdn"];
string MyUserName = Environment.UserName;
string MyDomainName = Environment.UserDomainName;
string MyComputerName = System.Net.Dns.GetHostName();
string MyIPAddress = System.Net.Dns.GetHostEntry(MyComputerName).AddressList[0].ToString();

//Retrieving Client Machine details
System.Net.IPAddress[] strClientIPAddress = System.Net.Dns.GetHostAddresses(Environment.MachineName);
string strClientMachineName = Environment.MachineName.ToString().Trim();
string strClientUserName = Environment.UserName.ToString().Trim();
string strClientDomainName = Environment.UserDomainName.ToString().Trim();
string strClientOSVersion = Environment.OSVersion.ToString().Trim();

string[] computer_name = System.Net.Dns.GetHostEntry(Request.ServerVariables["remote_addr"]).HostName.Split(new Char[] { '.' });
computer_name[0].ToString();

string getUserHostAddress = HttpContext.Current.Request.UserHostAddress;
string getUserHostName = HttpContext.Current.Request.UserHostName;


谢谢,
萨斯瓦塔


[更正的代码格式]


Thanks,
Saswata


[Corrected code formatting]

推荐答案

string getUserHostAddress = HttpContext.Current.Request.UserHostAddress;
string getUserHostName = HttpContext.Current.Request.UserHostName;



已关闭,但 HttpContext.Current.Request.UserHostAddress
指本地(即服务器计算机).


这应该满足您的需求:



Were close, but HttpContext.Current.Request.UserHostAddress
Referes to the local (ie server machine).


This shoul get what you need:

Request.ServerVariables("REMOTE_ADDR");
Request.ServerVariables("REMOTE_HOST");



但是主机名在Internet上基本上是没有意义的.这是一个有用的参考:

http://www.w3schools.com/asp/coll_servervariables.asp [ ^ ]



But the hostname is largely meaningless across the Internet. This is a useful ref:

http://www.w3schools.com/asp/coll_servervariables.asp[^]


这篇关于检索客户端的计算机名称和IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 07:31