-
Notifications
You must be signed in to change notification settings - Fork 0
/
VanityBreaker.cs
67 lines (57 loc) · 2.02 KB
/
VanityBreaker.cs
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
using System.Text.RegularExpressions;
namespace VLN
{
static class VanityBreaker {
static HttpClientHandler handler = new HttpClientHandler()
{
AllowAutoRedirect = false
};
static HttpClient client = new(handler);
static string Request(string url)
{
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.Write("[*] Finding the origin....\r");
HttpResponseMessage response = client.Send(new HttpRequestMessage(HttpMethod.Head, url));
IEnumerable<String> location;
if (response.Headers.TryGetValues("Location", out location))
{
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("[⤷] The link redirects to: " + location.First());
return Request(location.First());
}
else
{
Console.WriteLine(" ");
return url;
}
}
public static void FindOrigin(string link)
{
if (!Uri.IsWellFormedUriString(link, UriKind.Absolute))
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("[-] Please input a valid link that includes protocol.");
return;
}
string result;
try {
result = Request(link);
} catch (Exception e)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"[-] Error: {e.Message}");
return;
}
if (result == link)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("[-] The link does not redirect to any website or page.");
}
else
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine($"[+] Final location: {result}");
}
}
}
}