The best way which was mentioned in the commend and which is written in the documentation is the following:
You can define escape characters. Using this way, it is also possible to put labels to be able, later, to make reference to some lines of the verbatim environment.
In the documenation of listings you can find in section 7 the following hint: How to reference line numbers (page 53).
Based on the given example here a complete MWE:
\documentclass{article}
\usepackage{listings}
\begin{document}
\lstset{escapeinside={(*@}{@*)}}
\begin{lstlisting}
if (i < 0)
i=0 (*@\label{commentI}@*)
j=1 end if
if (j < 0) j=0 (*@\label{commentII}@*)
end if
{ comment }
\end{lstlisting}
Lines \ref{commentI} to \ref{commentII}
\end{document}

Lines \ref{first} to \ref{last}? – Seamus Jan 2 at 12:26