Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Need a python code for this.

I have a file containing a port numbers and ip addresses in a string. I have to extract the ip addresses, calculate the port number according to the formula and compare it to the port number in the file and print the ones that dont match. If the ip address is W.X.Y.Z the formula for port number is 50000+200(Y)+Z [in other words port = W.X.Y.Z => 50000 + 200(y) + z]. The text file is of the following format.

exchangeA_5=53413 ;239.189.17.13 7990

exchangeA_6=53415 ;239.189.17.15 7990

exchangeA_e=53470 ;239.189.27.70 7990

exchangeA_5=53468 ;239.189.27.68 7990

What is the best way to do it?
Posted

1 solution

i think you can parse each line to get the name,port,ip.

VB
str = 'exchangeA_5=53413 ;239.189.17.13 7990'
index1 = str.find('=')
index2 = str.find(';')

elem1 = str[0:index1]
elem2 = str[index1+1:index2]
elem3 = str[index2+1:]
ip = elem3[0:elem3.find(' ')].split('.')


after that, you can calculate the port and verify it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900