Get IPAddress and HostName From PC or Laptop Using in Asp.Net C#

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


                             HTML COIDING

<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
            <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" />

                               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)
    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 "-";

First - Add New  - Form  - Select Label,Textbox,Button From ToolBox

Next - Add Namespaces - Network Call Ip Address for PC

Next - Run [F5] - Button Click - Show the Ip Address


Post a Comment