test_ping.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:netmon 作者: bullerian 项目源码 文件源码
def test_icmp_ping(self):
        """test icmp ping - compare to icmping utilite"""

        icmp_ping = Ping(IFACE, ICMP_NAME,  TIMEOUT, False)

        for ip in list(ipaddress.ip_network(TEST_NETWORK).hosts())[:5]:
            try:
                # need arping installed
                with os.popen('ping -c {} -t {} {}'.format(COUNT,
                                                           TIMEOUT,
                                                           str(ip)), 'r'):
                    # get exit code
                    ec = os.wait()[1] & 0xFF00
                res = icmp_ping.ping_host(str(ip))
            except PermissionException:
                print('Need root previlegies')
            if res[STATUS_INDEX] == ONLINE:
                self.assertTrue(ec == 0)
            else:
                self.assertFalse(ec == 0)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号