Created
March 6, 2015 15:19
-
-
Save riaqn/2f1596b162a46c803597 to your computer and use it in GitHub Desktop.
AWK script to atomically update IPSet based on ripe.net datebase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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