-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLocalizador.cs
More file actions
37 lines (33 loc) · 1.26 KB
/
Localizador.cs
File metadata and controls
37 lines (33 loc) · 1.26 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
using System;
using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
class Program
{
static async Task Main()
{
Console.Write("Digite o endereço IP: ");
string ip = Console.ReadLine();
string url = $"http://ip-api.com/json/{ip}";
using (HttpClient client = new HttpClient())
{
HttpResponseMessage response = await client.GetAsync(url);
if (response.IsSuccessStatusCode)
{
string jsonResponse = await response.Content.ReadAsStringAsync();
JObject data = JObject.Parse(jsonResponse);
Console.WriteLine("\nInformações do IP:");
Console.WriteLine($"País: {data["country"]}");
Console.WriteLine($"Região: {data["regionName"]}");
Console.WriteLine($"Cidade: {data["city"]}");
Console.WriteLine($"Latitude: {data["lat"]}");
Console.WriteLine($"Longitude: {data["lon"]}");
Console.WriteLine($"ISP: {data["isp"]}");
}
else
{
Console.WriteLine("Erro ao obter informações do IP.");
}
}
}
}