Created
March 8, 2020 22:58
-
-
Save reb311ion/c29748f295bb1166c11968ca76a6fff2 to your computer and use it in GitHub Desktop.
Tiny.cc client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Net; | |
using System.Text; | |
using System.Text.RegularExpressions; | |
namespace Tinycc | |
{ | |
class Program | |
{ | |
static int Main(string[] args) | |
{ | |
if (args.Length < 2) | |
{ | |
Console.WriteLine("tinycc.exe <LONG_URL> <SHORT_URL>"); | |
return 1; | |
} | |
else | |
{ | |
return tinyccAPI(args[0], args[1]); | |
} | |
} | |
public static int tinyccAPI(string logurl, string customurl) | |
{ | |
try | |
{ | |
WebRequest request = WebRequest.Create("https://tiny.cc/"); | |
HttpWebResponse TheRespone = (HttpWebResponse)request.GetResponse(); | |
StreamReader sourceCodeStream = new StreamReader(TheRespone.GetResponseStream(), Encoding.UTF8); | |
string sourceCode = sourceCodeStream.ReadToEnd(); | |
Tuple<string, string> paramId = getPostParamId(sourceCode); | |
string text = string.Format("url_{0}={2}&custom_{0}={3}&field_{0}=&referrer={1}", paramId.Item1, paramId.Item2, logurl, customurl); | |
WebRequest requestSend = WebRequest.Create("https://tiny.cc/ajax/create"); | |
requestSend.Method = "POST"; | |
byte[] byteArray = Encoding.UTF8.GetBytes(text); | |
requestSend.ContentType = "application/x-www-form-urlencoded"; | |
requestSend.ContentLength = byteArray.Length; | |
Stream dataStreamSend = requestSend.GetRequestStream(); | |
dataStreamSend.Write(byteArray, 0, byteArray.Length); | |
dataStreamSend.Close(); | |
string converted = ""; | |
using (WebResponse response = (HttpWebResponse)requestSend.GetResponse()) | |
{ | |
byte[] bytes = ReadFully(response.GetResponseStream()); | |
converted = Encoding.UTF8.GetString(bytes, 0, bytes.Length); | |
Console.WriteLine(converted); | |
} | |
return 0; | |
} | |
catch | |
{ | |
return -1; | |
} | |
} | |
public static Tuple<string, string> getPostParamId(string source) | |
{ | |
Regex urlReg = new Regex(@"url_[A-Za-z0-9]+", RegexOptions.Compiled | RegexOptions.IgnoreCase); | |
Regex customReg = new Regex(@"custom_[A-Za-z0-9]+", RegexOptions.Compiled | RegexOptions.IgnoreCase); | |
Regex referrerReg = new Regex("referrer[a-zA-Z\"= ]+ value=\"[a-zA-Z0-9=]+", RegexOptions.Compiled | RegexOptions.IgnoreCase); | |
MatchCollection urlMatch = urlReg.Matches(source); | |
MatchCollection customMatch = customReg.Matches(source); | |
MatchCollection referrerRegMatch = referrerReg.Matches(source); | |
String urlm = ""; | |
foreach (Match custom in customMatch) | |
{ | |
foreach (Match url in urlMatch) | |
{ | |
if(custom.ToString().Split("_")[1] == url.ToString().Split("_")[1]) | |
{ | |
urlm = url.ToString().Split("_")[1]; | |
} | |
} | |
} | |
String[] refr = referrerRegMatch[0].ToString().Split('"'); | |
String referrer = refr[refr.Length - 1]; | |
return Tuple.Create(urlm, referrer); | |
} | |
public static byte[] ReadFully(Stream input) | |
{ | |
byte[] buffer = new byte[16 * 1024]; | |
using (MemoryStream ms = new MemoryStream()) | |
{ | |
int read; | |
while ((read = input.Read(buffer, 0, buffer.Length)) > 0) | |
{ | |
ms.Write(buffer, 0, read); | |
} | |
return ms.ToArray(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment