<?php
Error_reporting (7);
Class MSN
{
Private $startcomm = 0;
Private $username = ';
Private $password = ';
Private $commend = ';
Private $domain = ';
Private $socket = ';
Private $challenge = ';
Private $status = Array ();
Private $data = Array ();
function Set_account ($username, $password)
{
$this->username = $username;
$this->password = $password;
}
function GetData () {
$buffer = "";
while (!feof ($this->socket)) {
$buffer. = fread ($this->socket,1024);
if (Preg_match ("//r/", $buffer)) {
Break
}
}
$this->checkdata ($buffer);
}
function GetData2 () {
$buffer = "";
while (!feof ($this->socket)) {
$buffer. = fread ($this->socket,1024);
if (Preg_match ("//r/n/r/n/", $buffer)) {
Break
}
}
$this->checkdata ($buffer);
}
function Checkdata ($buffer) {
if (Preg_match ()/lc/= (. +?) /ui ", $buffer, $matches)) {
$this->challenge = "lc=". $matches [1];
}
if (Preg_match (XFR 3 NS) ([0-9/./:]+?) (.*) ([0-9/./:]+?) /is ", $buffer, $matches)) {
$split = Explode (":", $matches [2]);
$this->startcomm = 1;
$this->msn_connect ($split [0], $split [1]);
}
if (Preg_match ("/tpf/=") ([a-za-z0-9]+?) /ui ", $buffer, $matches)) {
$this->nexus_connect ($matches [1]);
}
$split = Explode ("n", $buffer);
for ($i =0; $i <count ($split); $i + +) {
$detail = Explode ("", $split [$i]);
if ($detail [0] = = "LST") {
if (Isset ($detail [2])) $this->data[] = Array ($detail [1], UrlDecode ($detail [2]));
}
}
$this->status = Array ($this->data);
Echo $buffer;
}
function Msn_connect ($server, $port) {
if ($this->socket) {
Fclose ($this->socket);
}
$this->socket = @fsockopen ($server, $port, $errno, $errstr, 20);
if (! $this->socket) {
$this->status = Array (, ' MSN Authentication server cannot connect ');
return false;
} else {
$this->startcomm++;
$this->send_command ("VER"). $this->startcomm. "MSNP8 CVR0", 1);
$this->send_command ("CVR"). $this->startcomm. "0x0409 win 4.10 i386 MSNMSGR 6.2 msmsgs". $this->username,1);
$this->send_command ("USR"). $this->startcomm. "TWN I". $this->username,1);
}
}
function Send_command ($command) {
$this->commend = $command;
$this->startcomm++;
Fwrite ($this->socket, $command. "/r/n");
$this->getdata ();
}
function Nexus_connect ($TPF) {
$arr [] = "get/rdr/pprdr.asp http/1.0/r/n/r/n";
$curl = Curl_init ();
curl_setopt ($curl, Curlopt_url, "https://nexus.passport.com:443/rdr/pprdr.asp");
curl_setopt ($curl, Curlopt_returntransfer, 1);
curl_setopt ($curl, curlopt_verbose, 0);
curl_setopt ($curl, curlopt_header,1);
curl_setopt ($curl, Curlopt_httpheader, $arr);
curl_setopt ($curl, Curlopt_ssl_verifypeer, FALSE);
$data = curl_exec ($curl);
Curl_close ($curl);
Preg_match ("/dalogin= (. +?),/", $data, $matches);
if (!isset ($matches [1])) return false;
$split = Explode ("/", $matches [1]);
$headers [0] = "get/$split [1] http/1.1/r/n";
$headers [1] = "authorization:passport1.4 orgverb=get,orgurl=http%3a%2f%2fmessenger%2emsn%2ecom,sign-in=". $this->username. ", pwd=." $this->password. ", " . Trim ($this->challenge). "/r/n";
$curl = Curl_init ();
curl_setopt ($curl, Curlopt_url, "https://". $split [0]. ": 443/". $split [1]);
curl_setopt ($curl, Curlopt_returntransfer, 1);
curl_setopt ($curl, curlopt_verbose, 0);
curl_setopt ($curl, curlopt_followlocation,1);
curl_setopt ($curl, Curlopt_httpheader, $headers);
curl_setopt ($curl, curlopt_header,1);
curl_setopt ($curl, Curlopt_ssl_verifypeer, FALSE);
$data = curl_exec ($curl);
Curl_close ($curl);
Preg_match ("/t= (. +?)" /", $data, $matches);
if (!isset ($matches [1])) {
$this->status = Array (404, ' You entered the MSN account or password error ');
return false;
}
$this->send_command ("USR"). $this->startcomm. "TWN S t=". Trim ($matches [1]). "", 2);
$this->send_command ("CHG"). $this->startcomm. "HDN", 2);
$this->send_command ("SYN"). $this->startcomm. "0", 2);
$this->getdata2 ();
$this->send_command ("SYN"). $this->startcomm. "1 46 2", 2);
$this->getdata2 ();
$this->send_command ("CHG"). $this->startcomm. "Bsy");
$this->getdata ();
}
Public Function GetStatus ()
{
return $this->status;
}
}
$msn = new MSN;
$msn->set_account (' xx@hotmail.com ', ' xxxxx ');
$msn->msn_connect ("messenger.hotmail.com", 1863);
$data = $msn->getstatus ();
Print_r ($data);
?>