I am currently trying to script a task for my Bind9 server. The goal is to have the user input an IP address in the following format:
192.168.90.150
I would then like Python to take that IP address and dissect it into 4 different groupings in 4 different variables
192.168.90.150 would become...
first = 192
second = 168
third = 90
fourth = 150
I assume the "industry standard" way of doing this would be with regular expressions. I have tried to use the following search strings to identify groupings of 1-3 numeric characters separated by periods. The following didn't work.
ipaddy = raw_input('Enter IP address: ')
failsearch1 = re.search(r'\d+\.')
failsearch2 = re.search(r'\d\.')
failsearch3 = re.search(r'(\d)+\.')
for x in ipaddy:
a = search.failsearch1(x)
b = search.failsearch2(x)
c = search.failsearch3(x)
if a or b or c:
print('Search found')
The output of the code above is nothing.
I've also tried several other variants of these search strings. Does anyone have any ideas how I can turn a typical IP address (192.168.10.10) into 4 different groupings based on separation between periods?
Any advice would be appreciated. Thanks.