this is not a duplicate question. I already researched the provided links and the suggestions did not help. I did open a new question that hopefully provided some clarification.
Let me clarify my questions: My ultimate goal is to remove the duplicate IP addresses from the list. I primarily need help with the following issue: I keep running into issues with maintaining the integrity of the IP addresses whenever I try to apply code (itertools, 'for' loops, etc) that removes duplicates from the output.
In summary:
1.My output is a tuple containing the matching strings (ip addresses)
2.I convert the tuple to a list of lists - print(hop_list)
3.I index [0] on the list of lists to obtain the IP addresses I need - print(ips) Is this where the problem lies? the output doesn't look like a list of list?
4.I apply various code solutions to remove duplicate addresses but for some reason I lose the integrity of my IP addresses.
per exscript api docs: • anymatch: If a match is found and the regular expression has multiple groups, a tuple containing the matching strings from the groups is returned.
def ios_commands(job, host, conn): #function to execute IOS commands
conn.execute('terminal length 0')
conn.execute('tr {}'.format(DesAddr))
print('The results of the traceroute', repr(conn.response))
for hops in any_match(conn, r"((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)([ (\[]?(\.|dot)[ )\]]?(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3})"):
hop_list = list(hops) #create a list from tuple
ips = hop_list[0] #index on targeted addresses
print(list(uniqify(ips))) #filter out duplicates
print(hop_list) #so far so good, list of lists from tuple
['192.33.12.4', '192', '.4', '.', '4']
['192.33.12.4', '192', '.4', '.', '4']
['192.32.0.174', '192', '.174', '.', '174']
['192.32.0.190', '192', '.190', '.', '190']
['192.33.226.225', '192', '.225', '.', '225']
['192.33.226.237', '192', '.237', '.', '237']
['192.33.12.4', '192', '.4', '.', '4']
Print(ips) #index first value as that is the address I need
I was expecting something like: ['192.33.12.4', '192.33.12.4', etc]
192.33.12.4
192.33.12.4
192.32.0.174
192.32.0.190
192.33.226.225
192.33.226.237
192.33.12.4
print(list(uniqify(ips)))
This is an edited sample output and where I run into a problem with the address format
['1', '9', '.', '3', '2', '4']
['1', '9', '.', '3', '2', '4']
['1', '9', '.', '3', '2', '7', '4']
['1', '9', '.', '3', '2', '9']
['1', '9', '.', '3', '2', '6', '5']
['1', '9', '.', '3', '2', '6', '7']
['1', '9 ', '.', '3', '2', '4']