using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Net;
using System.Text;
using System.Net.Sockets;
/// <summary>
/// Summary description for IPaddress
/// </summary>
public class IPaddress
{
public IPaddress()
{
//
// TODO: Add constructor logic here
//
}
public string getIPaddress()
{
string hostName = Dns.GetHostName(); // Retrive the Name of HOST
Console.WriteLine(hostName);
return hostName;
}
// Retirve The Local IP Address
public string GetLocalIPAddress()
{
string ipadd = "";
var host = Dns.GetHostEntry(Dns.GetHostName());
foreach (var ip in host.AddressList)
{
if (ip.AddressFamily == AddressFamily.InterNetwork)
{
ipadd = ip.ToString();
}
}
return ipadd;
}
// Retrieve The Current Absolute URL
public string GetCurrentUrl()
{
string Path = System.Web.HttpContext.Current.Request.Url.AbsoluteUri;
return Path;
}
// Retrive Current Running Page Name
public string GetCurrentPagename()
{
string Path = System.Web.HttpContext.Current.Request.Url.AbsolutePath;
System.IO.FileInfo Info = new System.IO.FileInfo(Path);
string pageName = Info.Name;
return pageName;
}
}This code snippet is for how to Get IP Address And Host Name.
