Skip to content

Commit

Permalink
Create Subnetting.py
Browse files Browse the repository at this point in the history
  • Loading branch information
EmreOvunc authored Apr 28, 2017
1 parent 059a786 commit bf7d1a9
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions Subnetting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/python3
# Emre Ovunc info@emreovunc.com

# IP & Subnet
def Int2Bin(integer):
binary = '{0:b}'.format(integer)
return binary

def seperation(IPs, count):
sep = '.'.join(Int2Bin(int(IPs.split('.')[x])) for x in range(count))
return sep

IP = input('Enter an IP address: ')
Subnet = input('Enter the Subnet mask: ')

print('\nIP:', IP, "->", seperation(IP, 4))
print('Subnet:', Subnet, "->", seperation(Subnet, 4))

# Wild Card
def complement(number):
if number == '0':
number = '1'
elif number == '.':
pass
else:
number = '0'
return number

def find_wildcard(binary_subnet):
binary_list = list(binary_subnet)
wildcard = ''.join(complement(binary_list[y]) for y in range(len(binary_list)))
return wildcard

def convert_decimal(wildcard_Binary):
binary = {}
for x in range(4):
binary[x] = int(wildcard_Binary.split(".")[x], 2)
dec = ".".join(str(binary[x]) for x in range(4))
return dec

wildcard_binary = find_wildcard(seperation(Subnet, 4))
WildCard = convert_decimal(wildcard_binary)
print('Wildcard:', WildCard, '->', wildcard_binary)

0 comments on commit bf7d1a9

Please sign in to comment.