本文来自:http://www.cnblogs.com/lilei107/archive/2011/07/27/2118506.html
using System.Net;
// 在此处放置用户代码以初始化页面
string SessionID = HttpContext.Current.Request.UserHostAddress;
string strHostName = Dns.GetHostName(); //得到本机的主机名
IPHostEntry ipEntry = Dns.GetHostByName(strHostName); //取得本机IP
SessionID = SessionID +","+ ipEntry.AddressList[0].ToString();
Label1.Text = SessionID;
System.Diagnostics.Process p=new System.Diagnostics.Process();
p.StartInfo.CreateNoWindow=true;
p.StartInfo.UseShellExecute=false;
p.StartInfo.RedirectStandardOutput=true;
p.StartInfo.FileName="ipconfig";
p.StartInfo.Arguments="/all";
p.Start();
p.WaitForExit();
string s=p.StandardOutput.ReadToEnd();
Label1.Text+=","+s.Substring(s.IndexOf("Physical Address. . . . . . . . . :")+36,17);
------------------------
//
//获取指定域名的IP地址
//
string StringURL;
StringURL = "http://www.baidu.com/";
for (int i = 0; i < Dns.GetHostEntry(StringURL).AddressList.Length; i = i + 1)
{
MessageBox.Show(Dns.GetHostEntry(StringURL).AddressList[i].ToString());
}
//
//获取本机IP地址
//
string StringHost;
StringHost = Dns.GetHostName();
for (int i = 0; i < Dns.GetHostEntry(StringHost).AddressList.Length; i = i + 1)
{
MessageBox.Show(Dns.GetHostEntry(StringHost).AddressList[i].ToString());
}