1

I was working on Retrieving IP address and client machine name for few days on the internet (not on the local network)
so I found some ways for getting IP-address , but I couldn't find a way for getting client machine name or gathering some info about my web site users ?
I know there are many duplicate threads about this issue out there , but many of them are old or do n't work.
the below server side codes return SERVER NAME Not client computer name !

string UserHost_ComputerName4 = Dns.GetHostName();//Server Name
string UserHost_ComputerName5 = Environment.MachineName;//Server Name  

and the below line have error on user-side , but it works on server-side page running :

 string UserHost_ComputerName3 = Dns.GetHostEntry(Request.ServerVariables["REMOTE_ADDR"]).HostName.ToString();//Has Error

Would you lead me to a possible and workable ways (JavaScript or jQuery or server side) for getting client (users who are visiting my web site) machine name?

Himanshu
  • 31,810
  • 31
  • 111
  • 133
SilverLight
  • 19,668
  • 65
  • 192
  • 300

3 Answers3

4

Try this:

string PCName = Dns.GetHostEntry(Request.ServerVariables["REMOTE_ADDR"]).HostName;

But if you want Name of Host PC

string HostPCName = Dns.GetHostName();
Himanshu
  • 31,810
  • 31
  • 111
  • 133
3

As far as I remember, in order to get:

  • Request.ServerVariables["REMOTE_ADDR"]
  • Request.ServerVariables["REMOTE_HOST"]
  • Request.ServerVariables["REMOTE_USER"]

you have to enable Reverse DNS Lookup for you IIS.

p.s. atm I'm not able to test it myself, so I'm not quite sure if this will solve ur problem

Nika G.
  • 2,374
  • 1
  • 17
  • 18
  • thanks for comment : but Request.ServerVariables["REMOTE_ADDR"] works for me without any changing in iis and Request.ServerVariables["REMOTE_HOST"] returns a marvelous string starts with babylon ... – SilverLight Jul 14 '11 at 11:38
  • @LostLord are you making request to the page from the machine that is actually running IIS? in other words, are you making request to the localhost? if so this might explain the behavior. if not can you specify what kind of errors are there on user-side? – Nika G. Jul 14 '11 at 12:30
  • at first , i correct my first comment (thanks for answer) -- i have remote access to my server and i can test web pages on server or local! that server uses windows server 2008 and latest iis ver (installed by myself) -- after configure iis and dns in that server when u run that page in server browser every thing is working (but not ok - we still do n't have user's machine name) / and when i browse it by my personal computer we have error because of that line -- but remember this error can not tell you any thing , because it is on user side! – SilverLight Jul 14 '11 at 13:40
1

Not entirely sure on all the ways you can do this, but it would be possible through ActiveX, which could be a problem as that only works in some browsers. I don't believe there is a way you can do it with pure javascript, and it's not possible serverside as the server does not get access to such details of it's connected clients.

hdougie
  • 344
  • 4
  • 9
  • you are right / but why many people tell that those codes work for them / i found a script in vb that used activeX / but it only works on IE ... however i am so confused about this issue / – SilverLight Jul 14 '11 at 11:40