How to

get host name of IP address

Published: 13. December 2008 | Updated: 13. December 2008
License: Microsoft Public License (MS-PL)
Categories: Network
Tags: C# Network Webforms
Was this snippet helpful for you? YESYES / NONO

Get host name of current visitor or saved IP address

Import namespaces

using System.Web;
using System.Net;

Code

// get ip addresss
string ipAddress = HttpContext.Current.Request.UserHostAddress;

// get name from request
string name = HttpContext.Current.Request.UserHostName;

// get name from dns
IPHostEntry e = Dns.GetHostEntry(ipAddress);
name = e.HostName;
Send us feedback about this snippet »



Related Snippets: