学习jmeter时,想要模拟多ip登录,就想到写这样一个小脚本,用来获取可用ip
import os
path = './ip.txt'
file = open(path, 'a', encoding='utf-8')
for i in range(1,256):
cmd = 'ping'+' '+'192.168.176.'+str(i)
res = os.popen(cmd)
output_str2 = res.read() # 获得输出字符串
print(output_str2)
if '100% 丢失' in output_str2:
print('该ip未被使用:{}'.format(cmd))
file.write(cmd)
else:
print('该ip已被使用:{}'.format(cmd))
offuse.append(cmd)