资源简介
c# 设置ip代理,可自由切换代理IP,如果有代理IP列表...

代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
namespace test
{
public class Proxies
{
public static bool UnsetProxy()
{
return SetProxy(null null);
}
public static bool SetProxy(string strProxy)
{
return SetProxy(strProxy null);
}
public static bool SetProxy(string strProxy string exceptions)
{
InternetPerConnOptionList list = new InternetPerConnOptionList();
int optionCount = string.IsNullOrEmpty(strProxy) ? 1 : (string.IsNullOrEmpty(exceptions) ? 2 : 3);
InternetPerConnOption[] options = new InternetPerConnOption[optionCount];
//not use or use proxy server
options[0].m_Option = PerConnOption.INTERNET_PER_CONN_FLAGS;
options[0].m_Value.m_Int = (int)((optionCount < 2) ? PerConnFlags.PROXY_TYPE_DIRECT : (PerConnFlags.PROXY_TYPE_DIRECT | PerConnFlags.PROXY_TYPE_PROXY));
//proxy server
if (optionCount > 1)
{
options[1].m_Option = PerConnOption.INTERNET_PER_CONN_PROXY_SERVER;
options[1].m_Value.m_StringPtr = Marshal.StringToHGlobalAuto(strProxy);
//except for these addresses ...
if (optionCount > 2)
{
options[2].m_Option = PerConnOption.INTERNET_PER_CONN_PROXY_BYPASS;
options[2].m_Value.m_StringPtr = Marshal.StringToHGlobalAuto(exceptions);
}
}
// default stuff
list.dwSize = Marshal.SizeOf(list);
list.pszConnection = IntPtr.Zero;
list.dwOptionCount = options.Length;
list.dwOptionerror = 0;
int optSize = Marshal.SizeOf(typeof(InternetPerConnOption));
// make a pointer out of all that ...
IntPtr optionsPtr = Marshal.AllocCoTaskMem(optSize * options.Length);
// copy the array over into that spot in memory ...
for (int j = 0; j < options.Length; ++j)
{
IntPtr opt = new IntPtr(optionsPtr.ToInt32() + (j * optSize));
Marshal.StructureToPtr(options[j] opt false);
}
list.pOptions = optionsPtr;
// and then make a pointer out of the whole list
IntPtr ipcoListPtr = Marshal.AllocCoTaskMem((Int32)list.dwSize);
Marshal.StructureToPtr(list ipcoListPtr false);
// and finally call the API method!
int returnvalue = NativeMethods.InternetSetOption(IntPtr.Zero
InternetOption.INTERNET_OPTION_PER_CONNECTION_OPTION
ipcoListPtr list.dwSize) ? -1 : 0;
if (returnvalue == 0)
{ // get the error codes they might be helpful
retur
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-05-03 16:09 test\
文件 8108 2017-04-27 15:54 test\Class1.cs
文件 4972 2017-05-02 15:33 test\Form1.Designer.cs
文件 1520 2017-05-03 15:41 test\Form1.cs
文件 5817 2017-05-02 15:33 test\Form1.resx
文件 2022 2017-05-02 15:33 test\Form2.Designer.cs
文件 1742 2017-05-02 16:17 test\Form2.cs
文件 5817 2017-05-02 15:33 test\Form2.resx
文件 485 2017-04-27 14:44 test\Program.cs
目录 0 2017-04-27 14:44 test\Properties\
文件 1328 2017-04-27 14:44 test\Properties\AssemblyInfo.cs
文件 2860 2017-04-27 14:44 test\Properties\Resources.Designer.cs
文件 5612 2017-04-27 14:44 test\Properties\Resources.resx
文件 1091 2017-04-27 14:44 test\Properties\Settings.Designer.cs
文件 249 2017-04-27 14:44 test\Properties\Settings.settings
目录 0 2017-04-27 14:44 test\bin\
目录 0 2017-05-02 11:50 test\bin\Debug\
文件 27648 2015-08-18 16:24 test\bin\Debug\HttpHelper.dll
文件 13824 2017-05-03 15:41 test\bin\Debug\test.exe
文件 34304 2017-05-03 15:41 test\bin\Debug\test.pdb
文件 22472 2017-05-03 15:56 test\bin\Debug\test.vshost.exe
文件 490 2010-03-17 22:39 test\bin\Debug\test.vshost.exe.manifest
文件 8704 2017-05-02 15:22 test\bin\Debug\test1.exe
目录 0 2017-04-27 14:44 test\obj\
目录 0 2017-05-03 15:41 test\obj\Debug\
文件 1451 2017-04-27 20:56 test\obj\Debug\DesignTimeResolveAssemblyReferences.cache
文件 6969 2017-05-03 16:09 test\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
目录 0 2018-02-26 17:22 test\obj\Debug\TempPE\
文件 180 2017-05-02 15:33 test\obj\Debug\test.Form1.resources
文件 180 2017-05-02 15:33 test\obj\Debug\test.Form2.resources
文件 180 2017-04-27 21:34 test\obj\Debug\test.Properties.Resources.resources
............此处省略38个文件信息
相关资源
- C#百度地图源码
- Visual C#.2010从入门到精通配套源程序
- C# 软件版本更新
- C#屏幕软键盘源码,可以自己定制界面
- 智慧城市 智能家居 C# 源代码
- c#获取mobile手机的IMEI和IMSI
- C#实现简单QQ聊天程序
- 操作系统 模拟的 欢迎下载 C#版
- C#写的计算机性能监控程序
- 用C#实现邮件发送,有点类似于outlo
- MVC model层代码生成器 C#
- c#小型图书销售系统
- C# Socket Server Client 通讯应用 完整的服
- c# winform 自动登录 百度账户 源代码
- C#编写的16进制计算器
- C#TCP通信协议
- C# 数据表(Dataset)操作 合并 查询一
- C#语音识别系统speechsdk51,SpeechSDK51L
- 数据库备份还原工具1.0 C# 源码
-
[免费]xm
lDocument 节点遍历C# - EQ2008LEDc#开发实例
- DirectX.Capturec# winform 操作摄像头录像附
- c# 实现的最大最小距离方法对鸢尾花
- C#版保龄球记分代码
- C#自定义控件
- 基于c#的实验室设备管理系统621530
- C# 使用ListView控件实现图片浏览器(源
- C#简单窗体聊天程序
- C#指纹识别系统程序 报告
- c# 高校档案信息管理系统
评论
共有 条评论