在python中ping主机的最快方法? [英] Fastest way to ping a host in python?

查看:149
本文介绍了在python中ping主机的最快方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

¿使用python检查主机是否启动或关闭的最快方法是什么?.

¿Which is the fastest way to check if a host is up or down using python?.

我需要执行 ~ 120K ping,所以如果有一些假阴性也没关系.

I need to perform ~ 120K pings so it doesn't matter if there is a few of false negatives.

我有两种不同的方法:

  • 带有 scapy 的 ICMP 请求
  • 执行 os.system("ping -c 1 " . ip)

推荐答案

我猜应该是 Scapy,因为您可以一次将所有数据包发送到所有主机.

My guess would be Scapy, because you can send all packets to all hosts at once.

from scapy.all import *
packets = IP(dst=["www.google.com", "www.google.fr"])/ICMP()
results = sr(packets)

这篇关于在python中ping主机的最快方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆