public partial class Default3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Text = Dns.GetHostName();
IPHostEntry iphost = Dns.GetHostEntry(TextBox1.Text);
TextBox2.Text=iphost.AddressList[0].ToString();
}
}
用户名显示lenovo-b9b16e97是对的ip显示不对为::1 怎么解决?
{
protected void Page_Load(object sender, EventArgs e)
{
TextBox1.Text = Dns.GetHostName();
IPHostEntry iphost = Dns.GetHostEntry(TextBox1.Text);
TextBox2.Text=iphost.AddressList[0].ToString();
}
}
用户名显示lenovo-b9b16e97是对的ip显示不对为::1 怎么解决?
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> </div>
</form>
</body>
</html>
static string GetIpAddress(string hostName)
{
IPHostEntry iphost = Dns.GetHostEntry(hostName);
foreach (IPAddress var in iphost.AddressList)
{
if (var.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
{
return var.ToString();
}
}
return iphost.AddressList[0].ToString();
}//usage
string ip = GetIpAddress("localhost");