Last active
January 4, 2016 13:49
-
-
Save mrcrilly/8630288 to your computer and use it in GitHub Desktop.
Banned IPs
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
import sys | |
from ipaddress import IPv4Network, IPv4Address | |
def error_banned(ip_addr): | |
print "That's a banned IP: {}".format(str(ip_addr)) | |
def error_private(ip_addr): | |
print "That IP is in a private range: {}".format(str(ip_addr)) | |
def main(): | |
banned = ['192.168.0.0/255.255.0.0', '10.0.0.0/255.0.0.0'] | |
ip = IPv4Address(sys.argv[1].decode()) | |
if ip.is_private or ip.is_link_local: | |
error_banned(ip) | |
for network in banned: | |
if ip in IPv4Network(network.decode()): | |
error_private(ip) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment