#!/usr/bin/env python
# -*- coding:utf-8 -*-
import os,re
with open("ip.txt","w",encoding="utf-8") as f:
for i in range(20,30):
ip=os.popen("ping -n 1 192.168.72.%s"%i).read().strip()
f.write(ip)
with open("ip.txt",encoding="utf-8") as f_r,open("ip2.txt","w",encoding="utf-8") as f_w:
for i in f_r:
if "TTL" in i:
m = re.search("\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}", i)#用正则匹配IP
f_w.write("%s\n"%m.group())
时间: 2024-10-28 04:45:48