-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathOSINT_Reddit.cs
111 lines (104 loc) · 5.67 KB
/
OSINT_Reddit.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
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
using System;
using System.Collections.Generic;
using System.Net;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Xml.Linq;
namespace Reecon
{
class OSINT_Reddit
{
public static RedditInfo GetInfo(string name)
{
RedditInfo redditInfo = new() { Exists = false };
var aboutPage = Web.GetHTTPInfo($"https://www.reddit.com/user/{name}/about.json", "Reecon (https://github.com/Reelix/reecon)");
if (aboutPage.StatusCode == HttpStatusCode.OK)
{
redditInfo.Exists = true;
var redditProfileInfo = JsonDocument.Parse(aboutPage.PageText);
JsonElement creationDate = redditProfileInfo.RootElement.GetProperty("data").GetProperty("created_utc");
JsonElement commentKarma = redditProfileInfo.RootElement.GetProperty("data").GetProperty("comment_karma");
redditInfo.CreationDate = DateTimeOffset.FromUnixTimeSeconds(long.Parse(creationDate.ToString().Replace(".0", ""))).LocalDateTime;
redditInfo.CommentKarma = commentKarma.GetInt64();
// Get Comments
List<OSINT_Reddit_Comment> commentList = new List<OSINT_Reddit_Comment>();
var commentsPage = Web.GetHTTPInfo($"https://www.reddit.com/user/{name}/comments.json", "Reecon (https://github.com/Reelix/reecon)");
if (commentsPage.StatusCode == HttpStatusCode.OK)
{
var commentInfo = JsonDocument.Parse(commentsPage.PageText);
JsonElement commentChildren = commentInfo.RootElement.GetProperty("data").GetProperty("children");
foreach (JsonElement comment in commentChildren.EnumerateArray())
{
OSINT_Reddit_Comment theComment = new OSINT_Reddit_Comment();
JsonElement commentData = comment.GetProperty("data");
theComment.Body = commentData.GetProperty("body").ToString();
JsonElement commentCreationDate = commentData.GetProperty("created_utc");
theComment.Created_UTC = DateTimeOffset.FromUnixTimeSeconds(long.Parse(commentCreationDate.ToString().Replace(".0", ""))).LocalDateTime;
theComment.Permalink = commentData.GetProperty("permalink").ToString();
commentList.Add(theComment);
}
}
redditInfo.CommentList = commentList;
// Get Submissions
List<OSINT_Reddit_Submission> submissionList = new List<OSINT_Reddit_Submission>();
try
{
var submissionsPage = Web.GetHTTPInfo($"https://www.reddit.com/user/{name}/submitted.json", "Reecon (https://github.com/Reelix/reecon)");
if (submissionsPage.StatusCode == HttpStatusCode.OK)
{
var submissionInfo = JsonDocument.Parse(submissionsPage.PageText);
JsonElement submissionChildren = submissionInfo.RootElement.GetProperty("data").GetProperty("children");
foreach (JsonElement submission in submissionChildren.EnumerateArray())
{
OSINT_Reddit_Submission theSubmission = new OSINT_Reddit_Submission();
/*
string subreddit;
string title;
public string selftext;
public string URL;
public DateTime created_utc;
*/
JsonElement submissionData = submission.GetProperty("data");
theSubmission.Subreddit = submissionData.GetProperty("subreddit").ToString();
theSubmission.Title = submissionData.GetProperty("title").ToString();
theSubmission.Selftext = submissionData.GetProperty("selftext").ToString();
theSubmission.URL = submissionData.GetProperty("url").ToString();
JsonElement submissionCreationDate = submissionData.GetProperty("created_utc");
theSubmission.Created_UTC = DateTimeOffset.FromUnixTimeSeconds(long.Parse(submissionCreationDate.ToString().Replace(".0", ""))).LocalDateTime;
submissionList.Add(theSubmission);
}
redditInfo.SubmissionList = submissionList;
}
}
catch (Exception ex)
{
Console.WriteLine("Error - Reddit Submitted Format Changed - Bug Reelix - " + ex.Message);
}
}
return redditInfo;
}
}
public class RedditInfo
{
public bool Exists = false;
public DateTime CreationDate;
public long CommentKarma;
public List<OSINT_Reddit_Comment> CommentList = new();
public List<OSINT_Reddit_Submission> SubmissionList = new();
// public List<OSINT_Reddit_Submitted> SubmissionList = new();
}
public class OSINT_Reddit_Comment
{
public string Body = "";
public DateTime Created_UTC;
public string Permalink = "";
}
public class OSINT_Reddit_Submission
{
public string Subreddit = "";
public string Title = "";
public string Selftext = "";
public string URL = "";
public DateTime Created_UTC = new DateTime();
}
}