Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to retrieve client machine name from javascript?

Posted on 2007-11-21
15
Medium Priority
?
14,818 Views
Last Modified: 2010-02-24
I have an ASP.NET application that is located on the server but is accessed from client machines. I need the application to retrieve computer name of the client computer that accesses the application. How can I do that using javascript?

P.S. I've already tried Environment.MachineName and Request.ServerVariables{"HOSTNAME"]. All these will only retrieve either IP Address or Server machine name. I need a client machine name

0
Comment
Question by:YZlat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 2
  • +1
15 Comments
 
LVL 7

Accepted Solution

by:
nisarkhan earned 1000 total points
ID: 20329011
>>How to retrieve client machine name from javascript?

you cant... because javascript is not a server_side script
0
 
LVL 35

Author Comment

by:YZlat
ID: 20329267
that's why I need javascript - because I need to retrieve the name of the client machine, the Internet explorer on which opens a web page.

In other words, from a web page opened on computer1 I need to get the name of the computer1. I cannot do that with server-side code, but that's done with client-side code. JavaScript is client-side language
0
 
LVL 33

Expert Comment

by:raterus
ID: 20329344
I believe the only way to truly do this is on the server, first you get the IP, and do a DNS lookup to get the computer name.  This will only work in an intranet where you have a local DNS server with all the computer names.
0
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 
LVL 35

Author Comment

by:YZlat
ID: 20330538
thanks raterus. and how do I do that? can you post some code?
0
 
LVL 9

Expert Comment

by:codeclay
ID: 20333457
Here is vbscript solution . http://www.codeproject.com/vbscript/userinfo.asp 
0
 
LVL 33

Expert Comment

by:raterus
ID: 20349754
I don't have any code to do this off the top of my head, I could google it probably just as easily as you could. ".net DNS lookup"
0
 
LVL 35

Author Comment

by:YZlat
ID: 20350353
I wrote this function to retrieve computer name, but I still need to get at least the IP Address of the client machine in order to pass it to my function. ANd Request.ServerVariables["REMOTE_ADDR"] gives me the IP of the localhost and not client computer

public string ComputerName(string ipaddr)
            {
                  System.Net.IPHostEntry objX;
                  string strHostName="";
 
                  try
                  {
                        //get the host dns entry
                        objX = System.Net.Dns.GetHostByAddress(ipaddr);

                        //get the hostname property
                        strHostName = objX.HostName;
                  }
                  catch (Exception ex)
                  {

                        //something went wrong (possibly no entry)

                  }//end try
                  return strHostName;
            }
0
 
LVL 33

Expert Comment

by:raterus
ID: 20350402
Try this to get the IP address

string ipaddress;
if (Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != "")
{
  ipaddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
}
else
{
  ipaddress = Request.ServerVariables["REMOTE_ADDR"];
}
0
 
LVL 35

Author Comment

by:YZlat
ID: 20350717
raterus, I get ipaddress=null
0
 
LVL 33

Expert Comment

by:raterus
ID: 20351314
You've got something weird going on in the configuration of your server.  REMOTE_ADDR should work, period, and not be the server's ip.
0
 
LVL 9

Expert Comment

by:codeclay
ID: 20355815
Wait a minute... when did it go server side ? I thought you wanted to do it client side...???
0
 
LVL 35

Author Comment

by:YZlat
ID: 20358129
It's really not important if it's done on client side or server-side, as long as I retrieve the name of the client machine, from which the web page is opened
0
 
LVL 33

Expert Comment

by:raterus
ID: 20373273
Keeping it simple, I think nisarkhan's first comment answered the question.  We were getting into server side scripting which wasn't really the original question.
0
 
LVL 35

Author Comment

by:YZlat
ID: 20373663
I guess you are right
0

Featured Post

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

660 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question