adb port forward. return local_port
769675
def forward(self, device_port, local_port=None):
        ''''''
        if local_port is None:
            for s, lp, rp in self.forward_list():
                if s == self.device_serial() and rp == 'tcp:%d' % device_port:
                    return int(lp[4:])
            return self.forward(device_port, next_local_port(self.server_host))
        else:
            self.cmd("forward", "tcp:%d" % local_port, "tcp:%d" % device_port).wait()
            return local_port
290436
def addr(self):
        """"""
        port = self.port
        if port:
            port = int(port)
        else:
            port = default_ports.get(self.scheme or 'http')
        return (self.host, port)
302113
def get_port_at(self, tile_id, direction):
        
        for port in self.ports:
            if port.tile_id == tile_id and port.direction == direction:
                return port
        port = Port(tile_id, direction, PortType.none)
        self.ports.append(port)
        return port
932302
def port(self):
        
        return self._val.port or DEFAULT_PORTS.get(self._val.scheme)
1246719
function getDevices(adbPath: string): Array<string> {
  try {
    const devicesResult = execSync(`${adbPath} devices`);
    return parseDevicesResult(devicesResult.toString());
  } catch (e) {
    return [];
  }
}
1177289
def find_available_port():
    
    s = socket.socket()
    s.bind(('localhost', 0))
    _address, port = s.getsockname()
    s.close()
    return port
1345773
def pick_port(self):
        """"""
        ports = set(range(self.min_port, self.min_port + self.port_range))
        return port_for.select_random(ports)
1002541
def _comports():
    '''
    
    '''
    return (pd.DataFrame(list(map(list, serial.tools.list_ports.comports())),
                         columns=['port', 'descriptor', 'hardware_id'])
            .set_index('port'))
1361187
@Override
  public InetAddress addressLocal()
  {
    SocketChannel s = _channel;
    
    if (s != null) {
      try {
        InetSocketAddress addr = (InetSocketAddress) s.getLocalAddress();
        
        return addr.getAddress();
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
    }
    else {
      return null;
    }
  }
457702
def port(self, port=None):
        
        if (port is None) or (port == self.__port):
            return self.__port
        # when port change ensure old socket is close
        self.close()
        # valid port ?
        if 0 < int(port) < 65536:
            self.__port = int(port)
            return self.__port
        else:
            return None
598258
def find_free_port
      socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
      socket.listen(1)
      port = socket.local_address.ip_port
      socket.close
      port
    end
559684
def getPort(self):
        
        disp = self.pbmanager.dispatchers[self.portstr]
        return disp.port.getHost().port
676917
def generate_local_port():
    """"""
    global _PREVIOUS_LOCAL_PORT
    if _PREVIOUS_LOCAL_PORT is None:
        try:
            with contextlib.closing(socket.socket(getattr(socket, 'AF_NETLINK', -1), socket.SOCK_RAW)) as s:
                s.bind((0, 0))
                _PREVIOUS_LOCAL_PORT = int(s.getsockname()[0])
        except OSError:
            _PREVIOUS_LOCAL_PORT = 4294967295  # UINT32_MAX
    return int(_PREVIOUS_LOCAL_PORT)
513505
def current(cls, service, port):
        
        host = socket.getfqdn()
        return cls(
            host=host,
            ip=socket.gethostbyname(host),
            port=port,
            metadata=service.metadata
        )
74874
def native_conn(self):
        """"""
        if self.__native is None:
            self.__native = self._get_connection()

        return self.__native
1324664
def client_port(self):
        """"""
        address = self._client.getpeername()
        if isinstance(address, tuple):
            return address[1]

        # Maybe a Unix domain socket connection.
        return 0
493154
def get_port(self, id_or_uri, port_id_or_uri):
        
        uri = self._client.build_subresource_uri(id_or_uri, port_id_or_uri, "ports")
        return self._client.get(uri)