f = \
'''
Product: DECNET Node: ALETHA Address(es): 1.1
Product: TCP/IP Node: aletha.ind.hp.com Address(es): 15.146.239.174
'''
lines = f.split('\n')
i = 1

###### To get the IP Address(es)
adapter_config = True
for line in lines:
if adapter_config:
# print line
import re
if (re.match("^Product:\s+",line)):
line1=re.split("\s+",line)
print line1[5]


I want to parse IP Address (15.146.239.174) from the above output, but in my script in line1[5] I am getting 1.1 and 15.146.239.174 both. How can I get only 15.146.239.174 thru my script.

Member Avatar for masterofpuppets

hi
I'm not sure if this will help you but here goes:

f = \
'''
Product: DECNET Node: ALETHA Address(es): 1.1
Product: TCP/IP Node: aletha.ind.hp.com Address(es): 15.146.239.174
'''
lines = f.split('\n')
i = 1

###### To get the IP Address(es)
adapter_config = True
for line in lines:
    if adapter_config:
    # print line
        import re
        if ( re.match( "^Product: TCP/IP\s+", line ) ):
            line1 = re.split( "\s+", line )
            print line1[ 5 ]

>>> 
15.146.239.174
>>>
Member Avatar for masterofpuppets

oh sorry I posted this already. :) :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.