Created
April 1, 2017 07:33
-
-
Save tiberiosantos/52ddb2bf90bbceb2094e09a37f921d80 to your computer and use it in GitHub Desktop.
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
# -*- coding: utf-8 -*- | |
try: | |
input = raw_input | |
except NameError: | |
pass | |
def ip2list(ip): | |
ip = [int(i) for i in ip.split('.')] | |
if len(ip) == 4: | |
return ip | |
else: | |
raise TypeError('Invalid conversion of ip to list') | |
def list2ip(array): | |
return '.'.join([str(a) for a in array]) | |
ip = ip2list(input('IP (0.0.0.0): ')) | |
mask = ip2list(input('Mask (0.0.0.0): ')) | |
network = [i & m for i, m in zip(ip, mask)] # ip and mask | |
imask = [~m & 0xff for m in mask] # invert mask | |
broadcast = [i | n for i, n in zip(imask, network)] # inverted mask or network | |
show = ''' | |
ip: {0} | |
mask: {1} | |
network: {2} | |
broadcast: {3} | |
''' | |
print(show.format(list2ip(ip), list2ip(mask), list2ip(network), | |
list2ip(broadcast))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment