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?
解决方案
i think you can parse each line to get the name,port,ip.
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.