Advertisement
Guest User

Untitled

a guest
Mar 17th, 2017
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.86 KB | None | 0 0
  1. [code]
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Net;
  6. using System.Net.Http;
  7. using System.Security.Cryptography;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using Newtonsoft.Json;
  11. using Newtonsoft.Json.Converters;
  12. using Newtonsoft.Json.Linq;
  13.  
  14. class Instagram
  15. {
  16.     private static Random Random = new Random();
  17.     private CookieContainer Cookies = new CookieContainer();
  18.     private async Task InitializeSession()
  19.     {
  20.         using (HttpClientHandler handler = new HttpClientHandler() { CookieContainer = Cookies, UseCookies = true, AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate })
  21.         using (HttpClient client = new HttpClient(handler))
  22.         using (HttpRequestMessage request = new HttpRequestMessage() { Method = HttpMethod.Get, RequestUri = new Uri("https://i.instagram.com/") })
  23.         {
  24.             request.Headers.UserAgent.ParseAdd("Instagram 7.1.1 Android (21/5.0.2; 480dpi; 1080x1776; LGE/Google; Nexus 5; hammerhead; hammerhead; en_US)");
  25.             request.Headers.Add("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
  26.             request.Headers.Add("accept-encoding", "gzip, deflate, sdch");
  27.             request.Headers.Add("accept-language", "en-US,en;q=0.8");
  28.             request.Headers.Add("upgrade-insecure-requests", "1");
  29.  
  30.             var response = await client.SendAsync(request);
  31.             var responseString = await response.Content.ReadAsStringAsync();
  32.         }
  33.     }
  34.     public async Task<string> CreateAccount(string Username, string First_Name, string Password, string Email)
  35.     {
  36.         try
  37.         {
  38.             await InitializeSession();
  39.  
  40.             var RegistrationContent = new
  41.             {
  42.                 username = Username,
  43.                 first_name = First_Name,
  44.                 password = Password,
  45.                 guid = RandomString(8) + "-" + RandomString(4) + "-" + RandomString(4) + "-" + RandomString(4) + "-" + RandomString(12),
  46.                 email = Email,
  47.                 device_id = "android-" + HMAC(Random.Next(1000, 9999).ToString()).ToString().Substring(0, Math.Min(64, 16))
  48.             };
  49.  
  50.             string Json = JsonConvert.SerializeObject(RegistrationContent, Formatting.Indented, new IsoDateTimeConverter());
  51.  
  52.             Dictionary<string, string> RegistrationRequest = new Dictionary<string, string>()
  53.             {
  54.                 { "signed_body",  HMAC(Json) + "." + Json },
  55.                 { "ig_sig_key_version", "4" }
  56.             };
  57.  
  58.             using (HttpClientHandler handler = new HttpClientHandler() { CookieContainer = Cookies, UseCookies = true, AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate })
  59.             using (HttpClient client = new HttpClient(handler))
  60.             using (HttpRequestMessage request = new HttpRequestMessage() { Method = HttpMethod.Post, RequestUri = new Uri("https://i.instagram.com/api/v1/accounts/create/"), Content = new FormUrlEncodedContent(RegistrationRequest) })
  61.             {
  62.                
  63.                 request.Headers.Host = "i.instagram.com";
  64.                 request.Headers.UserAgent.ParseAdd("Instagram 7.1.1 Android (21/5.0.2; 480dpi; 1080x1776; LGE/Google; Nexus 5; hammerhead; hammerhead; en_US)");
  65.                 request.Headers.Add("Accept-Language", "en-US");
  66.                 request.Headers.Add("Accept-Encoding", "gzip");
  67.                 request.Headers.Add("Cookie2", "$Version=1");
  68.                 request.Headers.Add("X-IG-Connection-Type", "WIFI");
  69.                 request.Headers.Add("X-IG-Capabilities", "BQ==");
  70.  
  71.                 var response = await client.SendAsync(request);
  72.                 var responseString = await response.Content.ReadAsStringAsync();
  73.                
  74.                 JObject JS = JObject.Parse(responseString);
  75.  
  76.                 if ((string)JS["status"] != "fail")
  77.                 {
  78.                     if ((bool)JS["account_created"] == true)
  79.                     {
  80.                         return "Account Created Successfully!";
  81.                     }
  82.                     else
  83.                     {
  84.                         if ((string)JS["errors"][" username"] != null)
  85.                             return "Error: " + (string)JS["errors"]["username"];
  86.  
  87.                         if ((string)JS["errors"]["password"] != null)
  88.                             return "Error: " + (string)JS["errors"]["password"];
  89.  
  90.                         if ((string)JS["errors"]["email"] != null)
  91.                             return "Error: " + (string)JS["errors"]["email"];
  92.  
  93.                         return "Error: Unknown";
  94.                     }
  95.                 }
  96.                 else
  97.                 {
  98.                     if ((bool)JS["spam"] == true)
  99.                         return "Error: Instgram thinks request is spam, change IP?";
  100.  
  101.                     return "Error: " + (string)JS["feedback_message"];
  102.                 }
  103.             }
  104.         }
  105.         catch (Exception ex) { return "Error: " + ex.Message; }
  106.     }
  107.     private static string HMAC(string String)
  108.     {
  109.         var keyByte = Encoding.UTF8.GetBytes("3f0a7d75e094c7385e3dbaa026877f2e067cbd1a4dbcf3867748f6b26f257117");
  110.         using (var hmacsha256 = new HMACSHA256(keyByte))
  111.         {
  112.             hmacsha256.ComputeHash(Encoding.UTF8.GetBytes(String));
  113.             return ByteToString(hmacsha256.Hash).ToLower();
  114.         }
  115.     }
  116.     private static string ByteToString(byte[] buff)
  117.     {
  118.         string sbinary = "";
  119.         for (int i = 0; i < buff.Length; i++)
  120.             sbinary += buff[i].ToString("X2");
  121.         return sbinary;
  122.     }
  123.     private static string RandomString(int length)
  124.     {
  125.         const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  126.         return new string(Enumerable.Repeat(chars, length).Select(s => s[Random.Next(s.Length)]).ToArray()).ToLower();
  127.     }
  128. }[/code]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement