python从ip端口 获取数据,如何使用Python提取IP地址和端口号并进行比较

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值