脚本判断当前局域网内有多少可用ip地址

作者: LifeSecret 2017-01-17 14:53:31

今儿也不知道是怎么了,网络故障遍地开花,有的是网卡不知道怎么的被禁用了,有的是网线被大妈拖地的时候给搞掉了。


 


其中有些问题是,无法拿到地址,手动设置吧,又不知道哪些可用,哪些已经备用,所以就写了如下的脚本,判断一下下啦。


 


#!/usr/bin/env python


import os


import sys


import re


import commands


a = commands.getoutput("fping -a -g 192.168.0.0/24 2>/dev/null > ./ip.linshi.txt")


weihao = []


for line in open("./ip.linshi.txt"):


#print line


results=line.replace("\n","").split(".")


#print results[3]


weihao.append(results[3])


print "current in use ip list:"


print weihao


keyongweihao = []


for i in range(1,200):


if str(i) in weihao:


continue


else:


keyongweihao.append(i)


print


print "current you can use the following ip:"


print keyongweihao






 


本文永久更新地址:http://www.linuxdiyf.com/linux/27894.html

相关资讯