Iniitla Commit
This commit is contained in:
commit
456c22e820
9 changed files with 215 additions and 0 deletions
51
bin/awsparser.dart
Normal file
51
bin/awsparser.dart
Normal file
|
@ -0,0 +1,51 @@
|
|||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:awsparser/awsparser.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
Future<void> main(List<String> arguments) async {
|
||||
print(">> WELCOME <<");
|
||||
print(">> Downloading AWS IP Range list..");
|
||||
// First, download the AWS IP Ranges config
|
||||
Dio dio = new Dio();
|
||||
Response<dynamic> awsResponse =
|
||||
await dio.get("https://ip-ranges.amazonaws.com/ip-ranges.json");
|
||||
|
||||
if (awsResponse.statusCode! == 200) {
|
||||
// Get body as string
|
||||
AWSJson aws = AWSJson.parse(awsResponse.data as Map<String, dynamic>);
|
||||
|
||||
print(">> Generating IP blocklist");
|
||||
|
||||
String blockListv4 = "";
|
||||
String blockListv6 = "";
|
||||
|
||||
for (var entry in aws.prefixes) {
|
||||
blockListv4 += "${entry.ip_prefix} AWS IPv4\n";
|
||||
}
|
||||
for (var entry in aws.ipv6_prefixes) {
|
||||
blockListv6 += "${entry.ipv6_prefix} AWS IPv6\n";
|
||||
}
|
||||
|
||||
print(">> Stripping trailing newline");
|
||||
blockListv4 = blockListv4.trim();
|
||||
blockListv6 = blockListv6.trim();
|
||||
|
||||
print(">> Report complete");
|
||||
print(">> Saving to ipv4_ranges.txt");
|
||||
|
||||
File fi = File("ipv4_ranges.txt");
|
||||
await fi.open(mode: FileMode.write);
|
||||
await fi.writeAsString(blockListv4);
|
||||
|
||||
print(">> Saving to ipv6_ranges.txt");
|
||||
fi = File("ipv6_ranges.txt");
|
||||
await fi.open(mode: FileMode.write);
|
||||
await fi.writeAsString(blockListv6);
|
||||
|
||||
print(">> Goodbye!");
|
||||
} else {
|
||||
print("/!\\ FATAL ERROR /!\\ Failed to download the IP Range list");
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue