Tags

, , , ,


Client/Remote Machine Name, IPAddress and Host IPAddress in Asp.net

Client Machine Name: JEETENDRA
Client Machine IPAddress: 192.168.0.191
Client Machine IPAddress: 192.168.0.191
Client Machine IPAddress over proxy: 192.168.0.191
Host Address: 192.168.0.132

To Get Client or Remote Computer Name and IP Address, can use the followings::

<hr />
Client Machine Name:
<%
System.Net.IPHostEntry host;
host = System.Net.Dns.GetHostByAddress(Request.ServerVariables[“REMOTE_HOST”].ToString());
Response.Write(host.HostName.ToString());
%>
<br />
Client Machine IPAddress:
<%
Response.Write(HttpContext.Current.Request.UserHostAddress.ToString());
%>
<br />
Client Machine IPAddress:
<%
Response.Write(HttpContext.Current.Request.ServerVariables[“REMOTE_ADDR”].ToString());
%>
<br />
Client Machine IPAddress over proxy:
<%
if(Request.ServerVariables[“HTTP_X_FORWARDED_FOR”]==null)
{
Response.Write(Request.ServerVariables[“REMOTE_ADDR”].ToString());
}
else
{

Response.Write(Request.ServerVariables[“HTTP_X_FORWARDED_FOR”].ToString());
}
%>
<br />
Host Address:
<%
string strHostName = System.Net.Dns.GetHostName();
string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();
Response.Write(clientIPAddress);
%>
<br />
<hr />

enjoy!

Advertisements