I am trying to draw this picture
I tried
\documentclass[border=2mm,tikz]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{3dtools}
\tikzset{intersection of line trough/.code args={#1 and #2 with plane containing #3 and normal #4}{%
\pgfmathsetmacro{\ltest}{abs(TD("#2o#4")-TD("#1o#4"))}%
\ifdim\ltest pt<0.01pt
\message{Plane and line are parallel!^^J}
\pgfmathsetmacro{\myd}{0}
\else
\pgfmathsetmacro{\myd}{(TD("#3o#4")-TD("#1o#4"))/(TD("#2o#4")-TD("#1o#4"))}%
\fi
\pgfmathsetmacro{\myP}{TD("#1+\myd*#2-\myd*#1")}%
\pgfkeysalso{insert path={%
(\myP)
}}
}}
\begin{document}
\tdplotsetmaincoords{60}{65}
\begin{tikzpicture}[scale=1,tdplot_main_coords,line join = round, line cap = round, declare function={a = 3;b = 4;}]
\path
(0,0,b+2) coordinate (M)
(0,0,-b) coordinate (N);
\begin{scope} [canvas is xy plane at z=0]
\draw[thick] (-a,-a) rectangle (a,a);
\end{scope}
\begin{scope} [canvas is xy plane at z=a]
\draw[thick] (-a,-a) rectangle (a,a);
\end{scope}
\path[overlay][intersection of line trough={(M) and (N) with plane containing (0,0,0) and normal (0,0,1)}] coordinate (I);
\path[overlay][intersection of line trough={(M) and (N) with plane containing (0,0,a) and normal (0,0,1)}] coordinate (J);
\foreach \p in {M,N,I,J}
\draw[fill=black] (\p) circle (1pt);
\foreach \p/\g in {M/90,N/-90,I/0,J/0}
\path (\p)+(\g:3mm) node{$\p$};
\draw[thick] (M) -- (N) ;
\end{tikzpicture}
\end{document}
How can I draw dashed lines correctly?