Get IPAddress and HostName From PC or Laptop
Get the IPAddress and HostName From Pc Or Laptop Button Click in Asp.Net C#.
Download Coding
Download
DEMO
HTML COIDING
Get the IPAddress and HostName From Pc Or Laptop Button Click in Asp.Net C#.
Download Coding
Download
DEMO
HTML COIDING
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<p>
<asp:Label ID="Label1" runat="server" Text="IPAddress"></asp:Label>
<asp:TextBox ID="txtIPAddress" runat="server"></asp:TextBox>
<asp:Label ID="Label2" runat="server" Text="HostName"></asp:Label>
<asp:TextBox ID="txtHostName" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit" />
<div>
</div>
</form>
</body>
</html>
C# CODING
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Sockets;
using System.IO;
public partial class IPGET : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
GetComputer_LanIP();
}
protected string GetComputer_LanIP()
{
string HostName = System.Net.Dns.GetHostName();
IPHostEntry ipEnt = System.Net.Dns.GetHostEntry(HostName);
foreach (IPAddress ipAddress in ipEnt.AddressList)
{
if (ipAddress.AddressFamily.ToString() == "InterNetwork")
{
txtIPAddress.Text = ipAddress.ToString();
txtHostName.Text = ipEnt.HostName.ToString();
return ipAddress.ToString();
}
}
return "-";
}
}
0 comments:
Post a Comment