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 o开发者_运维技巧f the network that I am connected to?
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 ?)
精彩评论