• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 8264
  • Last Modified:

How to get IP address of each terminal (which is running the ASP.NET application) instead of the hosting machine's IP address?

If my ASP.NET application runs on an IIS server, and there is a group of severl WYSE thin client terminals which runs this application (i think it has their own IP address), i found if I used the traditional way to get IP address (the code listed at the end), the IP address or hostname shown on these terminals are the same: hosting machine's IP address or hostname. Apparently, it's not what I want: each terminal shows their own IP address or hostname when they run this application. Is there any way to show their own IP address in their browser? Any comment is welcome. Below is my code which works well to get the first byte of the IP address of the hosting machine, thanks a lot!

IPHostEntry HostInfo = Dns.GetHostByName("");  
IPAddress [] IpAddr = HostInfo.AddressList;      //IP string
byte [] IpBytes = IpAddr[0].GetAddressBytes();      //four bytes
string FirstByte = IpBytes[0].ToString();
0
heyday2004
Asked:
heyday2004
  • 2
2 Solutions
 
surajgupthaCommented:
Request.ServerVariables[28] should give the Hosting ip Address

Request.ServerVariables[32] should give the ip address of the machine that runs it
Request.ServerVariables[33] should give the ip address of the machine that runs it

Please let me know if it works
0
 
mmarinovCommented:
Hi heyday2004,

you can use Request.UserHostAddress to get IP address of the computer that request the application and
Request.UserHostName to get the DNS name

Regards!
B..M
mmarinov
0
 
heyday2004Author Commented:
Thanks a lot for the answer. I tried Request.ServerVariables[32], Request.UserHostName (supposed to print out a user machine name instead of IP address), but both printed "127.0.0.1",  I know this local host IP address, i.e.  when a machine sends an IP packet to it ( 127.0.0.1) , it is sending to itself. Of course, what I want is not that, i want the client machine's user name. Any help is appreciated! Thanks a lot!
0
 
heyday2004Author Commented:
I got the hostname successfully finally. The code is below:
string client = Request.UserHostName;
return (System.Net.Dns.GetHostByAddress(client)).HostName;

So now, i just wonder why  Request.UserHostName returns IP address? thanks a lot.

      
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now