-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathLookup.cs
More file actions
58 lines (56 loc) · 2.25 KB
/
Lookup.cs
File metadata and controls
58 lines (56 loc) · 2.25 KB
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
using System;
using System.Drawing;
using System.Net;
using System.Text.Json;
namespace Reecon;
public static class Lookup
{
public static void Scan(string[] args)
{
if (args.Length != 2)
{
Console.WriteLine("Lookup Usage: reecon -lookup 8.8.8.8");
return;
}
string ip = args[1];
// No HTTPS without paying. Weird... But it is free, so hey!
var result = Web.GetHttpInfo($"http://ip-api.com/json/{ip}");
if (result.StatusCode == HttpStatusCode.OK && result.PageText != null)
{
string pageText = result.PageText;
JsonDocument data = JsonDocument.Parse(pageText);
var jsonRoot = data.RootElement;
string status = jsonRoot.GetProperty("status").GetString() ?? "";
if (status != "success")
{
string message = jsonRoot.GetProperty("message").GetString() ?? "";
Console.WriteLine($"Lookup Error for {ip}: " + status);
if (message != "")
{
Console.WriteLine($"- Reason: {message}");
}
return;
}
string country = jsonRoot.GetProperty("country").GetString() ?? "";
string countryCode = jsonRoot.GetProperty("countryCode").GetString() ?? "";
string region = jsonRoot.GetProperty("regionName").GetString() ?? "";
string regionCode = jsonRoot.GetProperty("region").GetString() ?? "";
string city = jsonRoot.GetProperty("city").GetString() ?? "";
string isp = jsonRoot.GetProperty("isp").GetString() ?? "";
string org = jsonRoot.GetProperty("org").GetString() ?? "";
Console.WriteLine($"Lookup result for: {ip.Recolor(Color.Green)}");
Console.WriteLine($"Country: {country} ({countryCode})");
Console.WriteLine($"Region: {region} ({regionCode})");
Console.WriteLine($"City: {city}");
Console.WriteLine($"ISP: {isp}");
if (org != string.Empty)
{
Console.WriteLine($"Organisation: {org}");
}
}
else
{
Console.WriteLine($"Error - Unable to get information for {ip}");
}
}
}