Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8376735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:29:42+00:00 2026-06-09T15:29:42+00:00

i am developing asp.net website , now my problem is how to get the

  • 0

i am developing asp.net website , now my problem is how to get the lan connected ip address using c# code , for example open http://whatismyipaddress.com/ display the IP Information: 183.82.77.56 like that i have to get ip address , now i am writing like this

//Get Lan Connected IP address method
        public string GetLanIPAddress()
        {
            //Get the Host Name
            string stringHostName = Dns.GetHostName();
            //Get The Ip Host Entry
            IPAddress[] arrIpAddress1 = Dns.GetHostAddresses(stringHostName);

            IPHostEntry ipHostEntries = Dns.GetHostEntry(stringHostName);
            //Get The Ip Address From The Ip Host Entry Address List
            IPAddress[] arrIpAddress = ipHostEntries.AddressList;
            return arrIpAddress[arrIpAddress.Length - 1].ToString();
        }
        //Get Visitor IP address method
        public string GetVisitorIpAddress()
        {
            string stringIpAddress;
            stringIpAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
            if (stringIpAddress == null) //may be the HTTP_X_FORWARDED_FOR is null
            {
                stringIpAddress = Request.ServerVariables["REMOTE_ADDR"];//we can use REMOTE_ADDR
                string add = HttpContext.Current.Request.UserHostAddress;
            }
            return "Your ip is " + stringIpAddress;
        }

but wrong outputs, please help me any one.

Thank u
hemanth

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:29:43+00:00Added an answer on June 9, 2026 at 3:29 pm

    Add this code

            foreach (IPAddress ipaddress in ipHostEntries.AddressList)
            {
                IPStr = ipaddress.ToString();
                return IPStr;
            }
            return IPStr;
    

    try this gateway address will be you required

       IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties();
            Console.WriteLine(ipProperties.HostName);
    
            foreach (NetworkInterface networkCard in NetworkInterface.GetAllNetworkInterfaces())
            {
                foreach (GatewayIPAddressInformation gatewayAddr in networkCard.GetIPProperties().GatewayAddresses)
                {
                    Console.WriteLine("Information: ");
                    Console.WriteLine("Interface type: {0}", networkCard.NetworkInterfaceType.ToString());
                    Console.WriteLine("Name: {0}", networkCard.Name);
                    Console.WriteLine("Id: {0}", networkCard.Id);
                    Console.WriteLine("Description: {0}", networkCard.Description);
                    Console.WriteLine("Gateway address: {0}", gatewayAddr.Address.ToString());
                    Console.WriteLine("IP: {0}", System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName()).AddressList[0].ToString());
                    Console.WriteLine("Speed: {0}", networkCard.Speed);
                    Console.WriteLine("MAC: {0}", networkCard.GetPhysicalAddress().ToString());
                }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a problem i am developing an asp.net mvc project. Website is in
I am developing a website in asp.net using dotnetnuke cms. I need to add
I am developing an asp.net website using typed dataset as DAL , everything works
I am developing a website using asp.net c# and I want to put a
Possible Duplicate: Get the MAC of ASP.NET website user i am developing a local
I'm developing ASP.NET 4.0 Website using SQL server 2008 with Membership Framework. It runs
I'm developing a website using Asp.Net 3.5 in Visual Studio 2008 and we use
I'm developing a website in asp.net and now I need to convert it to
I've been developing a simple website using asp.net MVC and I'm starting to add
I am a newbie and developing a website using ASP .Net 2.0 with C#

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.