Caspar Kleijne
Caspar Kleijne

Reputation: 21864

Detect the name of the network the server is connected to

When developing an application at home or at work I need to comment the code that sets the proxy on or off. Because at home I am on a different network than at work, at home I don't need to use the proxy.

WebProxy proxy = new WebProxy(Settings.ProxyAddress, Settings.ProxyPort);
proxy.Credentials = CredentialCache.DefaultCredentials;
this.Proxy = proxy;

I would like to wrap this statement in a if-clause that determines the name of the network. Like

if(isCorporateNetwork) {.....set proxy...};

I tried to detect it with:

IPGlobalProperties.GetIPGlobalProperties().DomainName;

But that results as an empty string. Probably because my personal laptop is not a member of the domain. (However access to the network is granted by sending my credentials to the proxy, own devices are allowed to use the corporate network this way.)

How can I detect the name of the network that I am connected to?

Upvotes: 4

Views: 1195

Answers (1)

jgauffin
jgauffin

Reputation: 101130

Try to lookup your IP-address using DNS. (If you got a private IP you need to get the public through STUN or similar)

(This is just a different approach since yours seems to be the way to go: How to find FQDN of local machine in C#/.NET ?)

Upvotes: 1

Related Questions