Saturday, 9 April 2011

How To Get IP Address Of A Machine

 Getting Ip address of local machine...

Make sure that you include the System.Net namespace in your code; otherwise the compiler will not know where to look for the DNS class. For more information on the DNS class and System.Net namespace, please refer to the online documentation for the .NET SDK.

Ip Address : <asp:Label ID="Lbl1" runat="server"></asp:Label>.


protected void Getip()
        string ipaddress;
        ipaddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
        ipaddress = Request.ServerVariables["REMOTE_ADDR"];
        IPAddress[] serveraddress = System.Net.Dns.GetHostAddresses(System.Net.Dns.GetHostName());
        string localip = Request.UserHostAddress;
        if (localip == "")
            if (serveraddress.Length == 1)
                ip = serveraddress[0].ToString();
                Lbl1.Text = ip;
                ip = serveraddress[1].ToString();


No comments:

Post a Comment