In principle you can use Hamiltonian mechanics also for dissipative systems, or fon systems which cannot be completely described by a Lagrangian.
When a Lagrangian is provided, the Legendre transformation connects the Lagrangian space of states -- with local coordinates $(t,q,\dot{q})$ -- with the Hamiltonian one -- with local coordinates $(t,q,p)$.
In local coordinates, the said one-to-one bi-differentiable map reads
$$p_k = \frac{\partial L(t,q,\dot{q})}{\partial \dot{q}^k}\:,\tag{0}$$
$$q^k =q^k\:,$$
$$t=t\:.$$
I stress that we can invert these relations as
$$\dot{q}^k = \dot{q}^k(t,q,p)\:,\tag{01}$$
$$q^k =q^k\:,$$
$$t=t\:.$$
where $\dot{q}^k(t,q,p)$ is a known function.
If, in a local Hamiltonian chart, we define the Hamiltonian function as usual
$$H(t,q,p) :=
-L(t,q,\dot{q}(t,q,p))+ \sum_{k} p_k\dot{q}^k(t,q,p)\:,$$
the following three identities pop out, where the known function in Eq.(01) pervasively enters,
$$\left.\frac{\partial H}{\partial t}\right|_{(t,q,p)}= -\left.\frac{\partial L}{\partial t}\right|_{(t,q, \dot{q}(t,q,p))}\:, \quad
\left.\frac{\partial H}{\partial q^k}\right|_{(t,q,p)}= -\left.\frac{\partial L}{\partial q^k}\right|_{(t,q, \dot{q}(t,q,p))},\quad \left.\frac{\partial H}{\partial p_k}\right|_{(t,q,p)}= \dot{q}^k(t,q,p)\tag{1}$$
The second pair directly produces the corresponding of the Euler-Lagrange equations in the Hamiltonian space.
The E-L equations for an unknown curve $\gamma(t) = (t,q(t),\dot{q}(t))$ in Lagrangian variables, in whole generality are written as
$$\left.\frac{d}{dt}\right|_{\gamma(t)}\frac{\partial L}{\partial \dot{q}^k}= \left.\frac{\partial L}{\partial q^k}\right|_{\gamma(t)}+ Q_k(\gamma(t))\:, \qquad \dot{q}^k(t)= \left.\frac{dq^k}{dt}\right|_{\gamma(t)}\:.$$
Above $L(t,q,\dot{q}) = T(t,q,\dot{q})+ V(t,q,\dot{q})$ includes all (non-reactive) forces which can be described in terms of a standard or generalized potential $V=V(t,q,\dot{q})$. The functions $Q_k(t,q,\dot{q})$ include all the remaining (non-reactive) forces which are usually dissipative. The typical case is $$Q_k= -\sum_k \gamma_k \dot{q}^k\tag{3}$$
for constants $\gamma_k \geq 0$.
Taking advantage of (0) and (1), if $\gamma$ satisfies the E-L equations in the Lagrangian setting, the associated curve in the Hamiltonian world
$$\hat{\gamma}(t) := (t, q(t), p(t))\quad with \quad p_k(t) = \left.\frac{\partial L}{\partial \dot{q}^k}\right|_{\gamma(t)}$$
satisfies the generalized Hamilton equations (and vice versa)
$$\frac{dp_k}{dt} = -\left.\frac{\partial H}{\partial q^k}\right|_{\hat{\gamma}(t)} + \left. \hat{Q}_{k}(t,q,p)\right|_{\hat{\gamma}(t)}\:, \quad \frac{dq^k}{dt} = \left.\frac{\partial H}{\partial p_k}\right|_{\hat{\gamma}(t)}\tag{2}$$
where, obviously, the dissipative generalized forces in Hamiltonian language are written as
$$\hat{Q}_{k}(t,q,p):= Q_{k}(t,q,\dot{q}(t,q,p))\:.$$
We are now in a position to answer the question on the ground of the equations (2).
Consider a Hamiltonian function $H=H(t,q,p)$, a set of generalized (dissipative) forces $\hat{Q}_{k}(t,q,p)$, and a curve $\hat{\gamma}(t)= (t,q(t),p(t))$ solution of (2). A direct computation immediately leads to
$$\left.\frac{d}{dt}\right|_{\hat{\gamma}(t)}H(t,q,p) = \left.\frac{\partial H}{\partial t}\right|_{\hat{\gamma}(t)} + \sum_k \left.\frac{dq^k}{dt} \hat{Q}_{k}(t,q,p)\right|_{\hat{\gamma}(t)}\:.$$
The conclusion is that, in the dissipative case, the known identity valid for the case of absence of dissipativie interactions fails and has to be corrected as written above.
In the specific case of Eq.(3), we have
$$\left.\frac{d}{dt}\right|_{\hat{\gamma}(t)}H(t,q,p) = \left.\frac{\partial H}{\partial t}\right|_{\hat{\gamma}(t)} - \sum_k \gamma_k \left.\left|\frac{dq^k}{dt}\right|^2\right|_{\hat{\gamma}(t)}\:.$$
It is here evident that even if the Hamltonian does not depend explicitily on $t$, the total energy -- when the Hamiltonian represents the energy of the system- is not conserved, but it decreases in view of the dissipative forces.
It is also possible to show that the added term to the standard Hamiltonian equations is responsible for the failure of Liouville theorem: dissipative terms imply that the volume in the phase space is not preserved under the evolution of the system.
(Reference: V. Moretti: Analytical Mechanics
Classical, Lagrangian and Hamiltonian Mechanics, Stability Theory, Special Relativity, Springer 2023)