测mysql对ip段是否连通_ping判断网络连通性(检测IP是否可达)

#shell

for x in `seq 1 255`

do

#echo $x

ip=10.10.1.$x

ping -c 2 $ip > /dev/null

if [ $? == 0 ];then

echo "$ip is alive"

else

echo "$ip is unavialable"

fi

done

#python3

import subprocess

import threading

import IPy

import queue

ip = IPy.IP('10.10.1.0/24')

num_worker_threads = 100

def do_work(item):

retcode = subprocess.call('ping -c 2 %s > /dev/null' % item, shell=True)

if retcode == 0:

#print("{0} is alive".format(item))

with open('alive.txt','a+') as f:

print(item, end='\n', file=f)

else:

#print("{0} is unreachable".format(item))

with open('unreachable.txt', 'a+') as f:

print(item, end='\n', file=f)

def worker():

while True:

item = q.get()

if item is None:

break

do_work(item)

q.task_done()

q = queue.Queue()

threads = []

for i in range(num_worker_threads):

t = threading.Thread(target=worker)

t.start()

threads.append(t)

for item in ip:

q.put(item)

# block until all tasks are done

q.join()

# stop workers

for i in range(num_worker_threads):

q.put(None)

for t in threads:

t.join()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值