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 8407489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:22:44+00:00 2026-06-09T23:22:44+00:00

I am trying to get the local intranet ip of a machine from code

  • 0

I am trying to get the local intranet ip of a machine from code running on that machine
Is there a definitive way to do this?

I have tried getting all the IPs and filtering by
10.0.0.0-10.255.255.255,172.16.0.0-172.31.255.255,192.168.0.0-192.168.255.255

Dns.GetHostEntry(Dns.GetHostName()).AddressList

but this seems a bit magic to me, i’d rather .net did the work, it also returns multiple ips due to me having VirtualBox installed

I have also tried the following

var localAddress =
    (
        from ni in NetworkInterface.GetAllNetworkInterfaces()
        where ni.NetworkInterfaceType != NetworkInterfaceType.Loopback
                && hostEntry.HostName.EndsWith(string.Concat(".", ni.Name))
        let props = ni.GetIPProperties()
        from unicastAddress in props.UnicastAddresses
        where unicastAddress.Address.AddressFamily == AddressFamily.InterNetwork
        select unicastAddress.Address).FirstOrDefault();

which does work, but would it work on other network configurations?

this bit concerns me hostEntry.HostName.EndsWith(string.Concat(".", ni.Name))

Has anyone got a better way?

  • 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-09T23:22:45+00:00Added an answer on June 9, 2026 at 11:22 pm

    You can’t reliably use a single IP as the machine could have multiple network cards or multiple IPs per network card. For example my laptop has both a wired network card and a wireless network card and is quite happy to grab two local IPs from my router via DHCP.

    Also in some fancy network setups (mostly corporate environments) you can have IP with different subnets able to talk to each via a router. I might have floor #6 in an office tower be 192.168.6.X and floor number 7 be 192.168.7.X and then have a router allow traffic across multiple subnets despite them being masked apart by the subnet mask.

    A better strategy would be to grab the list of local IPs, filter for loopback addresses (127.0.0.1) and then attempt to connect to the target machine.

    But if you just want to detect a local IP as “not public on the internet”, you can attempt to ping a public address (maybe your webserver?) with a time-to-live (TTL) of 1 hop. This won’t make it past any router if one is present, meaning it will fail if it can’t reach the public internet in 1 hop or less indicating that it is behind a firewall.

    Check out this great answer on stackoverflow which includes source code: Check if IP is in LAN (behind firewalls and routers)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get all Books from the server (local PHP script), that
I'm trying to get Symfony 2.0.14 running at my local PC but get this
i'm trying to get information from a remote server on my local machine. readyState
I'm trying to get a dump from MySQL to my local client. This is
Trying to get a local copy of mytracks from: mytracks google code source I
I'm trying to get a local git repository running on my machine using tortoisegit,
I'm trying to get a current web application running on my local machine, for
I'm trying to get a local copy of a website running that someone else
I am trying to get a list of local network computers. I tried to
why would I get this error when trying to do a local install of

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.