-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMx.cs
50 lines (43 loc) · 1.29 KB
/
Mx.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
using DnsClient;
using System.Text.RegularExpressions;
namespace gmail_checker
{
internal class Mx
{
private string Line { get; set; }
private string Domain { get; set; }
private LookupClient Lookup { get; set; }
const string Pattern = @"(?<=@)[\w\.-]+";
public Mx(string line)
{
Line = line;
Lookup = new LookupClient();
var matches = Regex.Matches(Line, Pattern);
if (matches.Count > 0)
{
Domain = matches[0].Value;
}
else
{
Domain = Line;
}
}
//check domain mx
public async Task<string[]> CheckMxAsync()
{
var result = await Lookup.QueryAsync(Domain, QueryType.MX);
var record = result.Answers.MxRecords().ToArray();
if (record.Length == 0)
{
return Array.Empty<string>();
}
return record.Select(x => x.Exchange.Value).ToArray();
}
public async Task<string[]> CheckGmailAsync()
{
var mxs = await CheckMxAsync();
var isGmailMx = mxs.Any(x => x.Contains("google.com"));
return new[] { Line, isGmailMx ? "t" : "f" };
}
}
}