PHP get 163, Gmail, 126 and other mailbox contact address

Source: Internet
Author: User
On the internet to find some, most of them have been invalidated, for this I have re-organized a bit, especially release 126 of the code, 163 is relatively easy to crawl; 126 a bit sick and a jump, more trouble

Copy the Code code as follows:


/**
* @file class.126http.php
* Get 126 Email address List
* @author Jvones Http://www.jvones.com/blog
* @date 2009-09-26
**/
Class http126
{
Private Function Login ($username, $password)
{
First step: Preliminary landing
$cookies = Array ();
$ch = Curl_init ();
curl_setopt ($ch, Curlopt_ssl_verifypeer, false);
curl_setopt ($ch, Curlopt_url, "https://reg.163.com/logins.jsp?type=1&product=mail126&url=http:// Entry.mail.126.com/cgi/ntesdoor?hid%3d10010102%26lightweight%3d1%26verifycookie%3d1%26language%3d0%26style% 3d-1 ");
curl_setopt ($ch, Curlopt_post, 1);
curl_setopt ($ch, Curlopt_postfields, "username=". $username. " @126.com&password= ". $password);
curl_setopt ($ch, Curlopt_cookiejar, Cookiejar);
curl_setopt ($ch, curlopt_header,1);
curl_setopt ($ch, Curlopt_timeout, TIMEOUT);
curl_setopt ($ch, Curlopt_returntransfer, true);
$str = curl_exec ($ch);
File_put_contents ('./126result.txt ', $str);
Curl_close ($ch);
Gets the Redirect_url jump address, which can be viewed from 126result.txt, matching the address in the $str return stream via a regular
Preg_match ("/replace\" (. *?) \ "\) \;/", $str, $mtitle);
$_URL1 = $mtitle [1];
File_put_contents ('./126resulturl.txt ', $redirect _url);
Step two: Jump to the top again $_URL1
$ch = Curl_init ($_URL1);
curl_setopt ($ch, Curlopt_timeout, TIMEOUT);
curl_setopt ($ch, Curlopt_returntransfer, true);
curl_setopt ($ch, Curlopt_cookiefile,cookiejar);
curl_setopt ($ch, Curlopt_cookiejar, Cookiejar);
curl_setopt ($ch, curlopt_header,1);
$str 2 = curl_exec ($ch);
Curl_close ($ch);
if (Strpos ($contents, "safe exit")!== false)
{
return 0;
}
return 1;
}
/**
* Get email Address Book-Addresses
* @param $user
* @param $password
* @param $result
* @return Array
*/
Public Function Getaddresslist ($username, $password)
{
if (! $this->login ($username, $password))
{
return 0;
}
$header = $this->_getheader ($username);
if (! $header [' Sid '])
{
return 0;
}
Test to find SID (very important) and host
File_put_contents ('./host.txt ', $header [' Host ']);
File_put_contents ('./sid.txt ', $header [' Sid ']);
Start to enter the simulation crawl
$ch = Curl_init ();
curl_setopt ($ch, Curlopt_url, "http://". $header [' Host ']. " /a/s?sid= ". $header [' Sid ']." &func=global:sequential ");
curl_setopt ($ch, Curlopt_cookiefile, Cookiejar);
curl_setopt ($ch, Curlopt_httpheader, Array ("Content-type:application/xml"));
$str = " pab:searchcontacts FN true user:getsign Atures pab:getallgroups ";
curl_setopt ($ch, Curlopt_post, 1);
curl_setopt ($ch, Curlopt_postfields, $STR);
curl_setopt ($ch, Curlopt_timeout, TIMEOUT);
Ob_start ();
Curl_exec ($ch);
$contents = Ob_get_contents ();
Ob_end_clean ();
Curl_close ($ch);
Get mail list from the page information username && emailaddress
Preg_match_all ("/ (. *) <\/string>/umsi ", $contents, $mails);
Preg_match_all ("/ (. *) <\/string>/umsi ", $contents, $names);
$users = Array ();
foreach ($names [1] as $k = $user)
{
$user = Iconv ($user, ' utf-8 ', ' gb2312 ');
$users [$mails [1][$k]] = $user;
}
if (! $users)
{
Return ' There is no contact in your mailbox ';
}
return $users;
}
/**
* Get Header Info
*/
Private Function _getheader ($username)
{
$ch = Curl_init ();
curl_setopt ($ch, Curlopt_url, "http://entry.mail.126.com/cgi/ntesdoor?hid=10010102&lightweight=1& Verifycookie=1&language=0&style=-1&username= ". $username." @126.com ");
curl_setopt ($ch, Curlopt_cookiefile, Cookiejar); Cookies currently in use
curl_setopt ($ch, Curlopt_cookiejar, Cookiejar); New Cookie returned by the server
curl_setopt ($ch, Curlopt_returntransfer, true);
curl_setopt ($ch, Curlopt_header, true);
curl_setopt ($ch, Curlopt_nobody, true);
$c
Preg_match_all ('/location:\s* (. *?) \r\n/i ', $content, $regs);
$refer = $regs [1][0];
Preg_match_all ('/http\:\/\/(. *?) \//i ', $refer, $regs);
$host = $regs [1][0];
Preg_match_all ("/sid= (. *)/I", $refer, $regs);
$sid = $regs [1][0];
Curl_close ($ch);
Return Array (' sid ' = = $sid, ' refer ' = ' = $refer, ' host ' and $host);
}
}
?>


The above introduces PHP to get 163, Gmail, 126 and other mailbox contact address, including the content, I hope that the PHP tutorial interested in a friend helpful.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.