http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 5489|回复: 5

[其他] 126注册返回IP段不正常

[复制链接]
发表于 2013-3-23 00:35:05 | 显示全部楼层 |阅读模式
[C#] 纯文本查看 复制代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using WindowsFormsRs;
using System.Net;
using System.Net.Sockets;
using System.Text.RegularExpressions;
using System.Runtime.InteropServices;
using DotNet.Utilities;
namespace _126注册
{
    public partial class Form1 : Form
    {
        #region 全局子段
        string KnSkyCookie = "";//全局cookie
        string envalue;//网页envalue
        string sid;//jsessionid=
        
        #endregion
        public Form1()
        {
            InitializeComponent();
        }
        #region 第一次登录取值
        string webhttp()
        {
            txtuser.Text = RanUser(true);
            string resolt = KnSkyHttp.KnSkyGet("http://reg.email.163.com/unireg/call.do?cmd=register.entrance&from=126mail", KnSkyCookie,
                ref KnSkyCookie, null, " [url]http://126.com/[/url]", 5000, true);

            envalue = QuMiddle(resolt, "envalue : \"", "\",");
            sid = QuMiddle(resolt, "sid : \"", "\",");
            return resolt;
        }
        #endregion
        #region 验证码
        void code()
        {
            webhttp();


            mailcode();
        }
        void mailcode()
        {
            string cookie = KnSkyCookie;
            //HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://reg.email.163.com/unireg/call.do?cmd=register.verifyCode&v=common/verifycode/vc_en&env=" + pgv_pvid(envalue).Trim() + "&t=" + NOWDATE().Trim());
            //req.Proxy = null;
            //HttpWebResponse res = (HttpWebResponse)req.GetResponse();
            //using (Stream stream = res.GetResponseStream())
            //{
            //    picCode.Image = Image.FromStream(stream);
            //}
            picCode.Image = Image.FromStream(KnSkyHttp.KnSkyPicture("http://reg.email.163.com/unireg/call.do?cmd=register.verifyCode&v=common/verifycode/vc_en&env=" + pgv_pvid(envalue).Trim() + "&t=" + NOWDATE().Trim(), cookie, ref cookie, "http://reg.email.163.com/unireg/call.do?cmd=register.entrance&from=126mail"));
        }
        #endregion
        #region 正则表达式
        public static string QuMiddle(string str, string str1, string str2)
        {
            Regex regex = new Regex(string.Format("(?<={0}).*?(?={1})", str1, str2), RegexOptions.Compiled);
            Match match = regex.Match(str);
            if (match.Success)
            {
                return match.Value;
            }
            return "未设置正确";
        }
        #endregion
        #region js方法
        public static object GetRSAPassword(string jsFilePath, string funcName, params object[] paramers)
        {
            using (StreamReader reader = new StreamReader(jsFilePath))
            {
                string sScript = reader.ReadToEnd();
                ScriptEngine se = new ScriptEngine(ScriptLanguage.JavaScript);
                object obj = se.Run(funcName, paramers, sScript);
                return obj;
            }
        }
        #endregion
        #region 取两个JS值
        string pgv_pvid(string ENV)
        {
            object str = GetRSAPassword(Application.StartupPath + "\\JScript1.js", "__$0", ENV);
            return str.ToString();
        }
        string NOWDATE()
        {
            object str = GetRSAPassword(Application.StartupPath + "\\JScript1.js", "I", "");
            return str.ToString();
        }
        #endregion
        #region 注册按钮
        private void btnlogin_Click(object sender, EventArgs e)
        {
            string user = txtuser.Text.Trim().ToLower();
            string code = txtcode.Text.Trim();
            textBox3.Text = KnSkyHttp.KnSkyPost("https://ssl.mail.163.com/regall/unireg/call.do;jsessionid=" + sid + "?cmd=register.start&reforward=common/reform&targetCmd=register.ctrlTop",
                   "name=" + user + "&flow=main&uid=" + user + "@126.com&password=jhty123&confirmPassword=jhty123&mobile=&vcode=" + code + "&from=126mail",
                    KnSkyCookie, ref KnSkyCookie, "", "http://reg.email.163.com/unireg/call.do?cmd=register.entrance&from=126mail", 5000, true);
            #region 苏飞的方法,试了没用返回401
            //   HttpHelper http = new HttpHelper();
            //   HttpItem item = new HttpItem()
            //   {
            //       URL = "https://ssl.mail.163.com/regall/unireg/call.do;jsessionid=" + sid + "?cmd=register.start&reforward=common/reform&targetCmd=register.ctrlTop",//URL     必需项
            //       Encoding = "utf-8",//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
            //       Method = "POST",//URL     可选项 默认为Get
            //       Timeout = 100000,//连接超时时间     可选项默认为100000
            //       ReadWriteTimeout = 30000,//写入Post数据超时时间     可选项默认为30000
            //       IsToLower = false,//得到的HTML代码是否转成小写     可选项默认转小写
            //       Cookie = KnSkyCookie,//字符串Cookie     可选项
            //       UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",//用户的浏览器类型,版本,操作系统     可选项有默认值
            //       Accept = "text/html, application/xhtml+xml, */*",//    可选项有默认值
            //       ContentType = "text/html",//返回类型    可选项有默认值
            //       Referer = "http://reg.email.163.com/unireg/call.do?cmd=register.entrance&from=126mail",//来源URL     可选项
            //       Allowautoredirect = true,//是否根据301跳转     可选项
            //       //CerPath = "d:\\123.cer",//证书绝对路径     可选项不需要证书时可以不写这个参数
            //       //Connectionlimit = 1024,//最大连接数     可选项 默认为1024
            //       Postdata = "name=" + user + "&flow=main&uid=" + user + "@126.com&password=jhty123&confirmPassword=jhty123&mobile=&vcode=" + code + "&from=126mail",//Post数据     可选项GET时不需要写
            //       //PostDataType=PostDataType.FilePath,//默认为传入String类型,也可以设置PostDataType.Byte传入Byte类型数据
            //       //ProxyIp = "192.168.1.105",//代理服务器ID     可选项 不需要代理 时可以不设置这三个参数
            //       //ProxyPwd = "123456",//代理服务器密码     可选项
            //       //ProxyUserName = "administrator",//代理服务器账户名     可选项
            //       ResultType = ResultType.Byte,//返回数据类型,是Byte还是String
            //   };

            //   //得到HTML代码
            //   HttpResult result = http.GetHtml(item);

            //   //取出返回的Cookie
            //   string cookie = result.Cookie;

            //   //得到返回的Byte数组
            //   byte[] bytelist = result.ResultByte;

            //   //返回的Html内容
            //textBox3.Text  = result.Html;
            #endregion
        }
        
        #endregion
        #region 执行验证码方法
        private void btnCode_Click(object sender, EventArgs e)
        {
            code();
        }
        #endregion
        #region 取随机帐号
        public string RanUser(bool Sleep)
        {
            lock (this)
            {
                if (Sleep) System.Threading.Thread.Sleep(10);
                string[] pinyins = new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };
                Random r = new Random();
                int l2 = r.Next(10000);
                Random ran = new Random();
                string username = "";
                for (int i = 0; i < 4; i++)
                {
                    username += pinyins[ran.Next(0, pinyins.Length)];

                }
                return username + l2;
            }
        }
        #endregion
        private void picCode_Click(object sender, EventArgs e)
        {
            mailcode();
        }
    }
}




1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
 楼主| 发表于 2013-3-23 00:41:26 | 显示全部楼层
代码发到C#传传看 里,希望谁能告诉我解决方案
发表于 2013-3-23 10:23:56 | 显示全部楼层
你这个其实就是想实现C#使用Http怎么注册126的邮箱是吧,如果是这样的话有空我可以帮你看看,今天休息啊,就不写代码了,楼主先研究下
 楼主| 发表于 2013-3-23 10:31:09 | 显示全部楼层
苏飞要帮帮忙啊,要不然易语言能POST掉的,C#做 不到我就绝望了
发表于 2013-3-23 10:47:34 | 显示全部楼层
写一首诗 发表于 2013-3-23 10:31
苏飞要帮帮忙啊,要不然易语言能POST掉的,C#做 不到我就绝望了

看你这话说的,这不是语言的问题,是你技术或者是我技术问题,语言怎么可能实现不了,咱们不能因为自身技术不行就说语言不行啊,这些太主观了楼主。
 楼主| 发表于 2013-3-23 10:55:31 | 显示全部楼层
我不是怀颖语言问题,自身技术确实不行,希望给个指点,我把源码发给了另一个群,他们都说取值没错,源码也没错,为什么返回IP段不正常,他们都想知道,所以我把源码发来请苏飞大哥调轼下,看下问题所在,好多人都在想知道为什么
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-5-3 06:27

© 2014-2021

快速回复 返回顶部 返回列表