Advertisement
scaredkys

DownDetector.dart

Apr 24th, 2020
1,132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.73 KB | None | 0 0
  1. // Simple CLI tool to detect if a website is up or down
  2. // Uses the DownFor API to get status of website
  3. // Written by SmallDoink#0666 | ScaredKYS
  4. import 'package:http/http.dart' as http;
  5. import 'dart:io';
  6. import 'dart:convert';
  7.  
  8. main(List<String> args) async {
  9.   // Read system arguments
  10.   var arg = args[0];
  11.   var url = 'https://api.downfor.cloud/httpcheck/'+arg; // Define URL for the http package
  12.   var response = await http.get(url); // Wait for the response to finish before defining
  13.   var body = jsonDecode(response.body); // Decode the JSON response
  14.   if (body['isDown'] == false) { // Handle the JSON response
  15.     print('The website is up!');
  16.   } else print('The website is down! (Status Code: ${body['statusCode']})') ;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement