Menu

[r2]: / trunk / WhatsappClient / WhatsAppHelper.cs  Maximize  Restore  History

Download this file

117 lines (105 with data), 3.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
* by Swen Kooij aka Kirk - swenkooij@gmail.com
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.Net;
using System.IO;
/// <summary>
/// A class with some functions to verify accounts, register accounts
/// </summary>
class WhatsAppHelper
{
/// <summary>
/// Enum that can be used to identify the Operating System of the user's device.
/// </summary>
public enum DeviceOS { iOS, Other };
/// <summary>
/// Generates a password based on the IMEI or Wifi Mac adress
/// </summary>
/// <param name="ImeiMac">The IMEI number or the Wifi Mac Adress</param>
/// <param name="OS">The mobile operating system the account was registered on.</param>
/// <returns>The generated password</returns>
public string generatePassword(string ImeiMac, DeviceOS OS)
{
if (OS == DeviceOS.iOS)
{
return md5(ImeiMac + ImeiMac);
}
else
{
return md5(ImeiMac.ToArray().Reverse().ToString());
}
}
/// <summary>
/// Checks if the account really exists
/// </summary>
/// <param name="Phonenumber">The phone number including the country code (eg: +316112233344)</param>
/// <param name="Password">The password of the whatsapp account</param>
/// <returns>True on existance and false when non-existent</returns>
public bool verifyAccount(string Phonenumber, string Password)
{
// Extract country code (first 3 characters of phone number - +)
string CountryCode = Phonenumber.Substring(0, 3).Replace("+", "");
Phonenumber = Phonenumber.Replace("+" + CountryCode, "0");
// Get page
string Html = httpGet("https://r.whatsapp.net/v1/exist.php?cc=" + CountryCode + "&in=" + Phonenumber + "&udid=" + Password);
// Verify
if (Html.Contains("<response status=\"ok\""))
return true;
else
return false;
}
/// <summary>
/// Makes a HTTP Get request to specified URL
/// </summary>
/// <param name="Url">The URL the request needs to be made at</param>
/// <param name="Timeout">Timeout specified in mili-seconds</param>
/// <returns>The body of the request (string)</returns>
private string httpGet(string Url, int Timeout)
{
try
{
System.Windows.Forms.MessageBox.Show(Url);
HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(Url);
Request.Method = "GET";
Request.Timeout = Timeout;
HttpWebResponse Response = (HttpWebResponse)Request.GetResponse();
StreamReader Reader = new StreamReader(Response.GetResponseStream());
return Reader.ReadToEnd();
}
catch (Exception e)
{
throw e;
}
}
/// <summary>
/// Makes a HTTP Get request to specified URL
/// </summary>
/// <param name="Url">The URL the request needs to be made at</param>
/// <returns>The body of the request (string)</returns>
public string httpGet(string Url)
{
return httpGet(Url, 3000000);
}
/// <summary>
/// Generates a MD5 hash from a string
/// </summary>
/// <param name="input">The string that needs to be hashed</param>
/// <returns>The MD5 hash in a string.</returns>
public string md5(string input)
{
MD5 md5 = MD5.Create();
byte[] inputBytes = Encoding.ASCII.GetBytes(input);
byte[] hash = md5.ComputeHash(inputBytes);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hash.Length; i++)
{
sb.Append(hash[i].ToString("X2"));
}
return sb.ToString().ToLower();
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.