11
# coding:utf-8 def maxnum(ipstr): ipstr = ipstr.split(‘ ‘)[1] return ipstr def minnum(ipstr): ipstr =ipstr.split(‘.‘)[3] ipstr = ipstr.split(‘ ‘)[0] return ipstr def ip_before(ipstr): ipstr_be =ipstr.split(‘.‘)[0]+‘.‘+ipstr.split(‘.‘)[1]+‘.‘+ipstr.split(‘.‘)[2]+‘.‘ return ipstr_be def main(): f = open(‘iptest.txt‘,‘r‘) for i in f.readlines(): i = i.strip() if minnum(i)==‘0‘: a=1 else: a=minnum(i) for j in range(int(a),int(maxnum(i))+1,1): ip =ip_before(i)+str(j) f1 = open(‘ipok.txt‘,‘a‘) print >>f1,ip f1.close() print ‘over‘ if __name__ == ‘__main__‘: main()
文件读取:
eg.
192.168.1.1 100
192.168.3.200 255
时间: 2024-10-29 10:46:37