想做个小程序,需要使用VPN改变IP地址,语言是C#.
---------------此为背景,割割割割割
1.以前看到有个叫[信鸽]的营销工具可以导入[91vpn]的代理线路并使用,谁知道是怎么实现的?2.还有什么办法让我得到C#程序里可以调用的VPN线路?(收费的也可)vpnc#工具

解决方案 »

  1.   

    需要更换IP,主要代码是:using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Text.RegularExpressions;
    using System.IO;
    using System.Threading;
    namespace zhangc
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            public string[] ini;
            public int page = 0;
            private void Form1_Load(object sender, EventArgs e)
            {
                wb.Navigate(new Uri("http://baidu.com"));            StreamReader sr = new StreamReader("./ini.txt", Encoding.Default);
                string txt = sr.ReadToEnd();
                ini = txt.Split(',');
                sr.Close();
                textBox1.Text = ini[0];
                textBox2.Text = ini[1];
            }        private void button1_Click(object sender, EventArgs e)
            {
                page = 1;            //搜索词赋值
                HtmlElement kw = wb.Document.All["kw"];
                kw.SetAttribute("value", textBox1.Text.ToString());
                //提交搜索            HtmlElement submit = wb.Document.All["su"];
                submit.InvokeMember("click");
                //wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(wb_DocumentCompleted);        }        public static string GetValue(string str, string s, string e)
            {
                Regex rg = new Regex("(?<=(" + s + "))[.\\s\\S]*?(?=(" + e + "))", RegexOptions.Multiline | RegexOptions.Singleline);
                return rg.Match(str).Value;
            }        private void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
            {
                foreach (HtmlElement archor in this.wb.Document.Links)
                {
                    archor.SetAttribute("target", "_self");
                }            //将所有的FORM的提交目标,指向本窗体
                foreach (HtmlElement form in this.wb.Document.Forms)
                {
                    form.SetAttribute("target", "_self");
                }            if (page == 1)
                {
                    //HtmlElementCollection link = wb.Document.GetElementById(textBox2.Text.ToString()).GetElementsByTagName("a");
                    //link[0].InvokeMember("click");                int all = wb.Document.GetElementsByTagName("table").Count;
                    for (int i = 0; i < all;i++ )
                    {
                        HtmlElement getem = wb.Document.GetElementsByTagName("table")[i];
                        if(getem.InnerHtml.Contains("张功"))
                        {
                            wb.Document.GetElementsByTagName("table")[i].GetElementsByTagName("a")[0].InvokeMember("click");
                            break;
                        }
                    }            }
            }        private void button2_Click(object sender, EventArgs e)
            {
                Form1_Load(null, null);
            }
        }
    }
      

  2.   

    vpn可以在网页中输入,用个webbrowse控件控制下不就行了
      

  3.   

    /// <summary>
            /// 清空ie代理
            /// </summary>
            /// <returns></returns>
            public bool SetCleanIEPoxy()
            {
                try
                {
                    //打开注册表键 
                    Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", true);
                    //设置代理不可用 
                    rk.SetValue("ProxyEnable", 0);
                    rk.Close();
                    return true;
                }
                catch { return false; }
            }
    /// <summary>
            /// 设置ie代理
            /// </summary>
            /// <returns></returns>
            public  bool SetIEPoxy()
            {
                try
                {
                    string TempPoxy = "";
                    int Tmi = 0;
                cs:
                    try
                    {
                        if (!MainForm.NowRead)
                            TempPoxy = MainForm.ProxyList[Rd.Next(ProxyIndex)].Trim();
                        else
                            TempPoxy = MainForm.ProxyList_Old[Rd.Next(ProxyIndex)].Trim();
                        if (TempPoxy.Trim() == "" || !MainForm.GetPage("http://www.baidu.com", TempPoxy, Encoding.UTF8).Contains("tieba.baidu.com"))
                        {
                            Thread.Sleep(500);
                            Tmi++;
                            if (Tmi > 10)
                                return false;
                            goto cs;
                        }
                    }
                    catch { return false; }                //打开注册表键 
                    Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", true);
                    //设置代理可用 
                    rk.SetValue("ProxyEnable", 1);
                    //设置代理IP和端口 
                    rk.SetValue("ProxyServer", TempPoxy);
                    rk.Close();
                    return true;
                }
                catch { return false; }
            }