You can't. Not all IP addresses will resolve to a distinct host name. Keep in mind, this is a host name assigned by an ISP and not the actual computer name and it will change whenever their DHCP renew hits. Also keep in mind this can be a slow operation
as the DNS server may not be the fastest to respond so you will want to use this sparingly.
Don't forget to mark useful responses as Answer if they helped you towards a solution.
1) check what returned in HttpContext.Current.Request.ServerVariables.Item("REMOTE_HOST")
2) if ip from #1 is correct, try to resolve it from the web server (from command prompt)
None
0 Points
25 Posts
Get Computer Name
Sep 30, 2014 09:06 PM|bora long|LINK
Dear all.
I have code:
Dim host1 As System.Net.IPHostEntry
Dim sClientName As String
host1 = System.Net.Dns.GetHostEntry(HttpContext.Current.Request.ServerVariables.Item("REMOTE_HOST"))
sClientName = host1.HostName.ToString
For get the host name ,but sometime i cannot get it from some computer's name. How can i do it?
All-Star
26071 Points
5892 Posts
Re: Get Computer Name
Sep 30, 2014 09:46 PM|markfitzme|LINK
You can't. Not all IP addresses will resolve to a distinct host name. Keep in mind, this is a host name assigned by an ISP and not the actual computer name and it will change whenever their DHCP renew hits. Also keep in mind this can be a slow operation as the DNS server may not be the fastest to respond so you will want to use this sparingly.
None
0 Points
25 Posts
Re: Get Computer Name
Oct 01, 2014 11:40 PM|bora long|LINK
Thanks.
If like this , how can i do ?
Can you help me?
All-Star
35149 Points
9075 Posts
Re: Get Computer Name
Oct 02, 2014 03:20 AM|smirnov|LINK
If you want to find the reason of the problem
1) check what returned in HttpContext.Current.Request.ServerVariables.Item("REMOTE_HOST")
2) if ip from #1 is correct, try to resolve it from the web server (from command prompt)
nslookup <xxx>
or
ping -a <xxx>
do you get the computer name?
3) compare your result with what is described in MSDN: http://msdn.microsoft.com/en-us/library/ms143998(v=vs.100).aspx
None
0 Points
25 Posts
Re: Get Computer Name
Oct 03, 2014 04:52 AM|bora long|LINK
Ok, Thanks you for your advice me.
Best regards.