Skip to content

Commit 9f723a2

Browse files
committed
Output RIR files and allow fetching from feed.php
Add github url to README
1 parent 2ba924c commit 9f723a2

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

README

+2
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,7 @@ This script came about after missing IPv6 GEO location functionality in Palo Alt
1616
It is also way easier to setup a ASN blocklist for questionable hosting such as "Limenet" https://bgp.tools/as/394711
1717

1818
Contact seth dot mos at dds dot nl
19+
Guthub: https://github.com/smos/ip-edl/
1920

2021
13-04-2024 Add newline when selecting multiple ASN or Countries
22+
25-05-2024 Add RIR files to the output, and fetch from feed.php

convert.php

+9-3
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ function validateCidr($cidr)
139139
}
140140

141141

142+
$rip = array();
142143
$cip = array();
143144
$guid = array();
144145
$asn = array();
@@ -182,9 +183,10 @@ function validateCidr($cidr)
182183
$cidr = "{$el[3]}/{$bits}";
183184
if(!validateCidr($cidr)) {
184185
echo "Address '{$el[3]}/{$bits}' is not valid in {$info['file']}, skipping\n";
185-
continue;
186+
continue 2;
186187
} else {
187188
$cip[$el[1]][] = $cidr;
189+
$rip[$rir][] = $cidr;
188190
// echo "{$el[3]}/{$bits} \n";
189191
// also save by guid for ASN lookup
190192
$guid[$el[7]][] = $cidr;
@@ -238,14 +240,18 @@ function validateCidr($cidr)
238240
// exit(0);
239241

240242
// print_r($res);
243+
echo "Write Aggregate RIR lists\n";
244+
foreach($rip as $rir => $arr) {
245+
file_put_contents("{$outdir}/rir/{$rir}.txt", implode("\n", $arr));
246+
247+
}
248+
241249
echo "Write Aggregate country lists from all RIRs\n";
242250
foreach($cip as $country => $arr) {
243251
file_put_contents("{$outdir}/country/{$country}.txt", implode("\n", $arr));
244252

245253
}
246254

247-
248-
249255
echo "Parse RIR DB for ASN routes\n";
250256
foreach($dbs as $rir => $db) {
251257
$i = 0;

feed.php

+20
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111

1212
}
1313

14+
function rlimit($cl) {
15+
return substr($cl, 0, 7);
16+
}
17+
1418
function climit($cl) {
1519
return substr($cl, 0, 2);
1620
}
@@ -19,6 +23,22 @@ function aslimit($as) {
1923
return substr($as, 0, 6);
2024
}
2125

26+
// Process Country value
27+
if(isset($_GET['rir'])) {
28+
$val = strtoupper(strip_tags($_GET['rir']));
29+
$items = preg_split("/;/", $val);
30+
$items = array_map('trim', $items);
31+
$items = array_map('rlimit', $items);
32+
// print_r($items);
33+
34+
foreach($items as $rir) {
35+
if(is_readable("{$outdir}/rir/{$rir}.txt")) {
36+
echo file_get_contents("{$outdir}/rir/{$rir}.txt");
37+
}
38+
}
39+
40+
}
41+
2242
// Process Country value
2343
if(isset($_GET['country'])) {
2444
$val = strtoupper(strip_tags($_GET['country']));

0 commit comments

Comments
 (0)