您的位置:首页 > 其它

获取服务器ip,本地ip,本在mac

2011-12-12 10:44 274 查看
本文来自: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());

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: