• 全部
  • C#综合技术
  • C#互联网桌面应用
  • AppLauncher
  • WinForm&WPF
  • C#开发新技术
  • 问答

该如何获得当前计算机的代理服务器地址及端口?

发财蛇 2004-10-14 04:51:34
~
...全文
377 点赞 收藏 8
写回复
8 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
felixwoo 2004-10-15
可以用WMI,但推荐使用注册表,因为效率要高。下面把两种方法都告诉你。

WMI:
string proxyServer = null;
ManagementClass mc = new ManagementClass("Win32_Proxy");
ManagementObjectCollection moc = mc.GetInstances();
foreach(ManagementObject mo in moc)
{
proxyServer=(string)mo["ProxyServer"]+":"+(string)mo["ProxyPortNumber"];
}

注册表:
private RegistryKey _InternetSettings = currentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", true);
string value = (string)_InternetSettings.GetValue( "ProxyServer", string.Empty );
_InternetSettings.Close();

用WMI可分别获得代理地址和端口,用注册表获得的是代理的完整地址(地址:端口)。
回复
saucer 2004-10-15
use System.Net.WebProxy's GetDefaultProxy method, for example

System.Net.WebProxy wp = System.Net.WebProxy.GetDefaultProxy();
Uri u = wp.Address;
Console.WriteLine(u.ToString());
Console.WriteLine(u.Host);
Console.WriteLine(u.Port);
回复
发财蛇 2004-10-15
ding~
回复
mbh0210 2004-10-15
学习中。。。。。。。。。
回复
happyRose 2004-10-15
都给人抢先说了。顶一下吧
回复
cancersyf 2004-10-15
Public Function GetProxyServerName() As String

Dim UseProxy As New Net.WebProxy()
Try 'if no proxy is specified, an exception is
'thrown by the frameworks and must be caught

Return UseProxy.GetDefaultProxy.Address.Host

Catch 'catch the error when no proxy is specified in IE

Return "Not Specified"

End Try

End Function


Public Function GetProxyServerPort() As String

Dim UseProxy As New Net.WebProxy()

Try 'if no proxy is specified, an exception is
'thrown by the frameworks and must be caught

Return UseProxy.GetDefaultProxy.Address.Port

Catch 'catch the error when no proxy is specified in IE

Return "Not Specified"

End Try

End Function
回复
wangxt 2004-10-14
帮你顶
回复
dahuzizyd 2004-10-14
试试WMI吧,
http://www.cnblogs.com/dahuzizyd/archive/2004/08/17/34058.aspx
后面评论里提供的程序也不错
回复
相关推荐
发帖
C#
创建于2007-09-28

10.5w+

社区成员

.NET技术 C#
申请成为版主
帖子事件
创建了帖子
2004-10-14 04:51
社区公告

让您成为最强悍的C#开发者