Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void GeoPing(string address, ITelegramBotClient botClient, Message message)
- {
- botClient.SendTextMessageAsync(message.Chat.Id, "Checking hostname...", replyMarkup: GetReturnButton());
- string url = $"https://geonet.shodan.io/api/geoping/{address}";
- {
- using (HttpClient client = new HttpClient())
- {
- HttpResponseMessage response = client.GetAsync(url).Result;
- string jsonString = response.Content.ReadAsStringAsync().Result;
- if (!jsonString.Contains("Invalid hostname") && !jsonString.Contains("\"packets_sent\":0"))
- {
- var json = JsonSerializer.Deserialize<GeoPingClass[]>(jsonString);
- if (json != null)
- foreach (var item in json)
- {
- if (cancelTokenSource.Token.IsCancellationRequested)
- return;
- if (item != null && item.from_loc != null)
- {
- botClient.SendTextMessageAsync(message.Chat.Id, $"Country: {item.from_loc.country}\nCity: {item.from_loc.city}\n" + (item.is_alive ? "Available ✅" : "Not available ❌"), cancellationToken: cancelTokenSource.Token, replyMarkup: GetReturnButton());
- Thread.Sleep(500);
- }
- }
- }
- else
- {
- currTask = 2;
- botClient.SendTextMessageAsync(message.Chat.Id, "Invalid hostname!", cancellationToken: cancelTokenSource.Token, replyMarkup: GetReturnButton());
- return;
- }
- }
- }
- botClient.SendTextMessageAsync(message.Chat.Id, "Completed!", cancellationToken: cancelTokenSource.Token, replyMarkup: GetButtons());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement