上篇我们说到了如何实现登陆,但是腾讯对某一个IP在某一段时间的登陆行为存在检测,对于存在异常的IP会出现验证码

但是腾讯的验证码比较难识别,或许是我对图形识别(匹配)的技术还认识的不够深刻

image

噪线,倾斜,字符连接,镂空,噪线字符同色.这些都是识别的难点,具体的算法我试过,识别成功率很低,技术不够没办法,好了偏题了,还是说ADSL拨号的实现

ADSL拨号需要调用windows api来实现

调用RASAPI32.DLL

image

ADSL的所有操作都要调用这个dll,详细的调用方法和参数,大家可以查询MSDN

不过对于我这种懒人,明白了原理,能使用拿来主义就拿哦

在codeplex上有个叫dotras的项目http://dotras.codeplex.com/这个项目封装了rasapi dll的操作,大家可以下载下来使用,不用自己在封装了,关于操作方法可以参见实例,下载过来后有示例的

 List<string> historyIps = new List<string>();
        private void ChangeIP()
        {
            SysConfig.IsChangeIp = true;
            QQHelper.WriteLog("更换IP");
        HANDUPCON:
            string oldIpAddress = "";
            RasConnection oldConn = null;
            GetIPAddress(out oldIpAddress, out oldConn);
            string entryName = "";
            if (oldConn != null)
            {
                entryName = oldConn.EntryName;
                RasIPInfo ipAddresses = (RasIPInfo)oldConn.GetProjectionInfo(RasProjectionType.IP);
                string oldIp = ipAddresses.IPAddress.ToString();
                ipAddresses = null;
                QQHelper.WriteLog("现在的IP是" + oldIp);
                bool isUp = false;
                try
                {
                    Console.WriteLine("开始挂断");
                    oldConn.HangUp(10 * 1000);
 
                    Thread.Sleep(SysConfig.RasHangUpSleepTime);
                    if (RasConnection.GetActiveConnectionById(oldConn.EntryId) != null)
                    {
                        Console.WriteLine("结束挂断失败,重新挂断");
                        goto HANDUPCON;
                    }
                    oldConn = null;
                    Console.WriteLine("结束挂断");
 
                    isUp = true;
                }
                catch (Exception ex)
                {
                    QQHelper.WriteLog("宽带连接挂断失败," + ex.Message);
                }
            }
        CHANGEIP:
            try
            {
                var dt = SqliteHelper.GetDataTable("select * from sys_config");
                RasDialer rs = new RasDialer();
                if (entryName == "")
                {
                    entryName = dt.Rows[0]["SC_NetEntryName"].ToString();
                }
                rs.EntryName = entryName;
                rs.PhoneBookPath = RasPhoneBook.GetPhoneBookPath(RasPhoneBookType.AllUsers);
                rs.Credentials = new NetworkCredential(dt.Rows[0]["SC_NetUser"].ToString(), dt.Rows[0]["SC_NetPwd"].ToString());
                dt.Dispose();
                rs.Dial();
                rs.Dispose();
 
            }
            catch (Exception ex)
            {
                QQHelper.WriteLog("宽带连接拨号失败," + ex.Message);
                Thread.Sleep(SysConfig.DialFaildSleepTime);
                goto CHANGEIP;
            }
            if (oldConn != null)
            {
                string ipAddresses = "";
                GetIPAddress(out ipAddresses, out oldConn);
                oldConn = null;
 
                if (oldIpAddress == ipAddresses)
                {
                    QQHelper.WriteLog("IP和上次重复,重新拨号");
                    Thread.Sleep(SysConfig.DialFaildSleepTime);
                    goto HANDUPCON;
                }
                else
                {
                    if (historyIps.Contains(ipAddresses))
                    {
                        QQHelper.WriteLog("IP和前" + SysConfig.IPLoopCount + "次重复,重新拨号");
                        Thread.Sleep(SysConfig.DialFaildSleepTime);
                        goto HANDUPCON;
                    }
                    if (historyIps.Count >= SysConfig.IPLoopCount)
                    {
                        historyIps.RemoveAt(0);
                        historyIps.Add(ipAddresses);
                    }
                    historyIps.Add(ipAddresses);
                }
 
                QQHelper.WriteLog("现在的IP是" + ipAddresses);
            }
            SysConfig.IsChangeIp = false;
        }

切换IP操作

  private void GetIPAddress(out string ipAddress, out RasConnection oldConn)
        {
            oldConn = null;
            ipAddress = "";
            var conns = RasConnection.GetActiveConnections();
            foreach (var conn in conns)
            {
                if (conn.Device.DeviceType.ToLower() == "pppoe")
                {
                    oldConn = conn;
                    break;
                }
            }
            conns = null;
            if (oldConn != null)
            {
                try
                {
                    RasIPInfo ipAddresses = (RasIPInfo)oldConn.GetProjectionInfo(RasProjectionType.IP);
                    ipAddress = ipAddresses.IPAddress.ToString();
                    ipAddresses = null;
                }
                catch { }
 
 
            }
        }

获取连接信息

 

 

题外话:由于最近失业了,呵呵,说大了,是离职,有很多事情需要处理交接,关于QQ 群组广告的源代码,不是我不放出来,主要由于一些代码涉及到公司版权,我不可能不做任何改变就放出来,有保密协议,我需要整理和修改一些代码的实现,以避免这些冲突,望大家理解

QQ 讨论组广告群发工具(已开发完成)索引

posted on 2012-04-22 16:43  rolends1986  阅读(3171)  评论(3编辑  收藏  举报