Check if a device identified by it IP is connected to the box
        :param ip: IP of the device you want to test
        :type ip: str
        :return: True is the device is connected, False if it's not
        :rtype: bool
760158
def is_device_connected(self, ip):
        
        all_devices = self.get_all_connected_devices()
        for device in all_devices:
            if ip == device['ipaddress']:
                return device['active'] == 1
        return False
901833
def is_ip(string):
    
    mo = re.match(r'(\d+)\.(\d+)\.(\d+)\.(\d+)', string)
    if mo is None:
        return False
    for group in mo.groups():
        if int(group) not in list(range(0, 256)):
            return False
    return True
96425
def ip(ip_addr, return_tuple=True):
    
    regex_ip = __re.compile("^((25[0-5])|(2[0-4][0-9])|(1[0-9][0-9])|([1-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|(1[0-9][0-9])|([1-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|(1[0-9][0-9])|([1-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|(1[0-9][0-9])|([1-9]?[0-9]))$")
    if return_tuple:
        while not regex_ip.match(ip_addr):
            print("Not a good IP.")
            print("Please try again.")
            ip_addr = input("Please enter a IP address in the following format x.x.x.x: ")
        return ip_addr
    elif not return_tuple:
        if not regex_ip.match(ip_addr):
            return False
        else:
            return True
1012317
public static function isIp($ip)
    {
        $segments = explode('.', $ip);

        if (count($segments) === 4) {
            foreach ($segments as $segment) {
                if (!is_numeric($segment)) {
                    return false;
                }
            }

            return true;
        } else {
            return false;
        }
    }
628277
def is_valid_ipv6(ip_str):
    
    try:
        socket.inet_pton(socket.AF_INET6, ip_str)
    except socket.error:
        return False
    return True
458007
def _detect_devices(self) -> None:
        ''''''
        devices_num = len(self.devices_list)
        if devices_num == 0:
            raise DeviceConnectionException(
                'No devices are connected. Please connect the device with USB or via WLAN and turn on the USB debugging option.')
        elif not self.device_sn and devices_num > 1:
            raise DeviceConnectionException(
                f"Multiple devices detected: {' | '.join(self.devices_list)}, please specify device serial number or host.")
        else:
            self.device_sn = self.devices_list[0]
        if self.get_state() == 'offline':
            raise DeviceConnectionException(
                'The device is offline. Please reconnect.')
854681
def _can_connect(ip, port):
    """"""
    cs = socket.socket()
    try:
        cs.connect((ip, port))
        cs.close()
        return True
    except socket.error:
        return False
284860
def check_internet_connection(self, remote_server: str = "api.isogeo.com") -> bool:
        
        try:
            # see if we can resolve the host name -- tells us if there is
            # a DNS listening
            host = socket.gethostbyname(remote_server)
            # connect to the host -- tells us if it's reachable
            sock = socket.create_connection((host, 80), 2)
            sock.close()
            return True
        except Exception as e:
            logging.error(e)
            return False
47505
def _check_dhcp_server(self, vboxnet):
        

        properties = yield from self._execute("list", ["dhcpservers"])
        flag_dhcp_server_found = False
        for prop in properties.splitlines():
            try:
                name, value = prop.split(':', 1)
            except ValueError:
                continue
            if name.strip() == "NetworkName" and value.strip().endswith(vboxnet):
                flag_dhcp_server_found = True
            if flag_dhcp_server_found and name.strip() == "Enabled":
                if value.strip() == "Yes":
                    return True
        return False
888877
def is_ip_filter(ip, options=None):
    '''
    
    '''
    return is_ipv4_filter(ip, options=options) or is_ipv6_filter(ip, options=options)
995063
def _on_connected(self, device):
        
        self._logger.debug("Device connected event: {}".format(device))

        self.connected = True
        self._connection_handle = device['connection_handle']
        self.device.connected = True
        self._audit('ClientConnected')
1283663
def connected(self):
        
        node_list = self.node_list()
        for node in node_list:
            bfs_list = self.forw_bfs(node)
            if len(bfs_list) != len(node_list):
                return False
        return True
261793
def maybe_ip_addr(addr):
    

    if six.PY2 and isinstance(addr, str):
        addr = unicode(addr)  # noqa
    try:
        return ipaddress.ip_address(addr)
    except ValueError:
        pass
    return str(addr)
302829
def connection_check(addr, port=80, safe=False, ipv6=None):
    '''
    
    '''
    return dns_check(addr, port, safe, ipv6)
707667
def check_connection(self):
        """"""
        host = self.urlparts[1]
        addresses = socket.getaddrinfo(host, 80, 0, 0, socket.SOL_TCP)
        args = {'host': host}
        if addresses:
            args['ips'] = [x[4][0] for x in addresses]
            self.set_result(_('%(host)s resolved to IPs %(ips)s') % args, valid=True)
        else:
            self.set_result(_('%(host)r could not be resolved') % args, valid=False)
499295
def check_ipv6(ip_str):
    

    try:
        socket.inet_pton(socket.AF_INET6, ip_str)
    except socket.error:
        return False
    return True
116749
def _do_tcp_check(self, ip, results):
        
        try:
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            sock.settimeout(1)
            sock.connect((ip, self.conf['tcp_check_port']))
        except:
            # Any problem during the connection attempt? We won't diagnose it,
            # we just indicate failure by adding the IP to the list
            results.append(ip)
        finally:
            sock.close()