# We will look at the client side of ‹nc› (netcat) in this script. # We left off with ‹dig› when we learned that email for ‹fi.muni.cz› # is handled by ‹relay.muni.cz›. Let's look at what would happen # next in our hypothetical mail scenario. # The MTA would learn the destination IP address and initiate an # SMTP session. I won't get into much detail, but let's talk about # ‹nc› for a bit. What ‹nc› does is basically what ‹cat› does, but # then sends the data over a network. It can both listen to # connections (with ‹-l›) or connect to existing services. We will # now use the latter mode. # In either case, whatever you send to ‹nc›, it will forward into # the network, and what falls out of the network connection, ‹nc› # will print to its ‹stdout›. Let's try with some SMTP: { sleep 5; # wait a bit for the remote server to greet us echo HELO aisa # tell them who we are (hostname) echo "MAIL FROM:" # and our mail address echo "RCPT TO:" # and the recipient of the email # At this point, the SMTP server will stop talking to us because it # does not want to send mail to ‹yes@me› -- that is fine, we didn't # want to actually spam anyone. The rest of the SMTP session would # mostly involve the actual message. } | nc relay.muni.cz 25 # 25 is the SMTP port # Let me just note that ‹nc› is not quite standardized. It's present # on many/most Unix systems, but the exact behaviour and switches # might differ. Be careful and read man pages. Let's try looking at # ‹nc› in server mode, in ‹listen.sh›.