Quantcast
Channel: MikroTik
Viewing all articles
Browse latest Browse all 15133

General • Re: Howto mark Amazon AWS traffic?

$
0
0
Hi EIKA,

here is s Powershell script which fetches the latest file from Amazon and converts it into a importable file for Mikrotik

right now its filtered on service "AMAZON" and region "eu-west-1" but you can remove the "| Where-Object { $_.service -eq "AMAZON" -and $_.region -match "eu-west-1" };" to get the full list.

After execution you will get a file in C:\temp\test.txt which can be uploaded to the router and import with the following command "/import file-name=amazon_aws.txt"

$Mikrotik_ListName = "AmazonAWS_IPS";
$ExportFilePath = "C:\temp\amazon_aws.txt";
$Response = Invoke-WebRequest -Uri "https://ip-ranges.amazonaws.com/ip-ranges.json" | ConvertFrom-Json;
$Filtered = $Response.prefixes | Where-Object { $_.service -eq "AMAZON" -and $_.region -match "eu-west-1" };
foreach ($ip in $Filtered)
{
write-host "Service: $($ip.service) CIDR: $($ip.ip_prefix)";
Add-Content $ExportFilePath "/ip firewall address-list add list=$($Mikrotik_ListName) address=$($ip.ip_prefix)";
}

Hope this will help

Best regards

Alex

Statistics: Posted by Cheuksin — Fri Jan 26, 2024 1:22 am



Viewing all articles
Browse latest Browse all 15133

Trending Articles