4

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?

Caspar Kleijne
  • 21,552
  • 13
  • 72
  • 102

1 Answers1

1

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 ?)

Community
  • 1
  • 1
jgauffin
  • 99,844
  • 45
  • 235
  • 372
  • If I need a public IP I need to get access to the proxy first ;) Wouldn't that be the same as wrapping it in a try catch and a retry then? – Caspar Kleijne Jul 01 '11 at 06:28