Skip to content

Instantly share code, notes, and snippets.

@riaqn
Created March 6, 2015 15:19
Show Gist options
  • Save riaqn/2f1596b162a46c803597 to your computer and use it in GitHub Desktop.
Save riaqn/2f1596b162a46c803597 to your computer and use it in GitHub Desktop.
AWK script to atomically update IPSet based on ripe.net datebase
#!/usr/bin/awk -f
BEGIN {
FS="|";
print "create china_new hash:net" | "ipset restore"
}
$2 == "CN" && $3 == "ipv4" {
prefix=32;
while ($5 > 1) {
--prefix;
$5 = $5/2;
}
print "add china_new " $4 "/" prefix | "ipset restore"
}
END {
print "swap china_new china" | "ipset restore"
print "destroy china_new" | "ipset restore"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment