How to use ping3 - 10 common examples

To help you get started, we’ve selected a few ping3 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kyan001 / ping3 / tests / test_ping3.py View on Github external
def test_ping_normal(self):
        delay = ping3.ping("example.com")
        self.assertIsInstance(delay, float)
github kyan001 / ping3 / tests / test_ping3.py View on Github external
def test_ping_ttl(self):
        delay = ping3.ping("example.com", ttl=64)
        self.assertIsInstance(delay, float)
        delay = ping3.ping("example.com", ttl=1)
        self.assertIsNone(delay)
github kyan001 / ping3 / tests / test_ping3.py View on Github external
def test_ping_seq(self):
        delay = ping3.ping("example.com", seq=199)
        self.assertIsInstance(delay, float)
github kyan001 / ping3 / tests / test_ping3.py View on Github external
def test_ping_bind(self):
        my_ip = socket.gethostbyname(socket.gethostname())
        dest_addr = "example.com"
        if my_ip == "127.0.0.1" or my_ip == "127.0.1.1":  # This may caused by /etc/hosts settings.
            dest_addr = my_ip  # only localhost can send and receive from 127.0.0.1 (or 127.0.1.1 on Ubuntu).
        delay = ping3.ping(dest_addr, src_addr=my_ip)
        self.assertIsInstance(delay, float)
github kyan001 / ping3 / tests / test_ping3.py View on Github external
def test_ping_ttl(self):
        delay = ping3.ping("example.com", ttl=64)
        self.assertIsInstance(delay, float)
        delay = ping3.ping("example.com", ttl=1)
        self.assertIsNone(delay)
github kyan001 / ping3 / tests / test_ping3.py View on Github external
def test_DEBUG(self):
        with patch("sys.stdout", new=io.StringIO()) as fake_out:
            with patch("ping3.DEBUG", True):
                delay = ping3.ping("example.com")
                self.assertTrue("[DEBUG]" in fake_out.getvalue())
github kyan001 / ping3 / tests / test_ping3.py View on Github external
def test_ping_hostunknown(self):
        not_exist_url = "not-exist.com"
        with patch("sys.stdout", new=io.StringIO()) as fake_out:
            self.assertFalse(ping3.ping(not_exist_url))
github kyan001 / ping3 / tests / test_ping3.py View on Github external
def test_ping_size(self):
        delay = ping3.ping("example.com", size=100)
        self.assertIsInstance(delay, float)
        with self.assertRaises(OSError):
            ping3.ping("example.com", size=99999)  # most router has 1480 MTU, which is IP_Header(20) + ICMP_Header(8) + ICMP_Payload(1452)
github kyan001 / ping3 / tests / test_ping3.py View on Github external
def test_ping_timeout_exception(self):
        with patch("ping3.EXCEPTIONS", True):
            with self.assertRaises(errors.Timeout):
                ping3.ping("example.com", timeout=0.0001)
github kyan001 / ping3 / tests / test_ping3.py View on Github external
def test_verbose_ping_normal(self):
        with patch("sys.stdout", new=io.StringIO()) as fake_out:
            ping3.verbose_ping("example.com")
            self.assertRegex(fake_out.getvalue(), r".*[0-9]+ms.*")

ping3

A pure python3 version of ICMP ping implementation using raw socket.

MIT
Latest version published 7 months ago

Package Health Score

68 / 100
Full package analysis

Similar packages