How to use the ping3.ping function in ping3

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 coreGreenberet / homematicip-samples / CheckPresenceOnPing / scan.py View on Github external
def main():
    if config is None:
        print("COULD NOT DETECT CONFIG FILE")
        return
    

    home = Home()
    home.set_auth_token(config.auth_token)
    home.init(config.access_point)

    if not home.get_current_state():
        return
    for ip in SCANABLE_DEVICES:
        try:
            res = ping3.ping(ip)
            if res != None:
                if DEACTIVATE_ON_PRESENCE:
                    for g in home.groups:
                        if isinstance(g, homematicip.group.SecurityZoneGroup) and g.active:
                            print("someone is at home. Deactivating security zones")
                            home.set_security_zones_activation(False,False)
                            return
                    print("someone is at home and security zones are deactivated -> do nothing")
                else:
                    print("someone is at home -> do nothing")
                return
        except gaierror:
            print("could not resolve {}. Marking it as \"not at home\"".format(ip))

    print("Noone is home -> activating security zones")
    home.set_security_zones_activation(ACTIVATE_INTERNAL_ZONE,ACTIVATE_EXTERNAL_ZONE)

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