If I am attached to the local LAN at work, I have to have my application access our server with an internal IP, otherwise, I'll want to use our exterior IP when in the wild.

Presently, I simply attempt to connect through the local IP after which try the exterior whether it fails... however the timeout takes a little too lengthy and I'm wondering if there's a method to discover what domain the equipment is attached to prior to trying.

Edit: Patrick> Basically, the application operates on a pc tablet that's attached to the local network a few occasions each day. It's roughly equal between the amount of occasions it connects within the network and also the occasions it connects in your area.

All machines possess a domain account when they're attached to the network (and also have domain accounts having a naming convention of like "LOCTabletx" where x is really a number provided to the equipment when it is ghosted.

What I am searching for is really a fast way to ascertain if the equipment is connected on our local network or even the internet. Using Atmosphere.UserDomainName will get me LOCTabletx and never the domain title.


Whether it helps anybody, I simply attempt to DNS Resolve the title of the machine will be able to guarantee is going to be around the network (among the servers). It really works sufficiently well for me personally.

Perhaps you have attempted:


You might have a look in the active IP addresses around the machine, and query for just one that creates the local network...

var x = NetworkInterface.GetAllNetworkInterfaces()
    .Where(ni => ni.OperationalStatus == OperationalStatus.Up)
    .SelectMany(ni => ni.GetIPProperties().UnicastAddresses);

// do something with the collection here to determine if you're on the right network.
// just looping & printing here for example.
foreach (var item in x)

And after you have determined the network that you are on, you can sign up for the System.Net.NetworkInformation.NetworkChange.NetworkAddressChanged event to deal with your pc jumping systems while your application is running.


This can return "NTLM" if not attached to the network.

You need to consider the Network Location Awareness API. On Home windows Vista or later, it enables you to definitely programmatically uncover which network you are attached to, and become informed if this changes.

It may be familiar for you as the "Is a house / work / public network?" dialog box.

One other way, but I'm not sure if it's really much better compared to other solutions is:


this can be a string that returns "Kerberos" underactive directory. Unsure what it really would say if not attached to the domain though.

Environment.UserDomainName ...provides you with the equipment title if you're not became a member of to some domain. It offers a superior the domain title if you're became a member of to some domain. For a piece of equipment that's became a member of to some domain from the network and out "in to the wild", Environment.UserDomainName continues to supply the domain title even when you reboot and log in (for your domain account). Your machine caches the domain qualifications for around thirty days.

Should you sign in for your machine account, then you'll obtain the machine title.