Network programming with Go
You write TCP and UDP clients and servers with the net package, resolve DNS, set deadlines and TLS correctly and build reliable network tools in your own lab network.
Level 301 · 19 lessons · 15 practice labs
Lessons
TCP and UDP
- The net package: Dial, Listen and Conn
- A TCP client: connect, write, read
- A concurrent TCP server
- Message framing: lines, length prefixes and bufio
- Deadlines: SetDeadline and DialContext
- Client and server over UDP
- Short task: a small line-based chat server
Name resolution and network info
- DNS queries with net.Resolver
- Addresses and ranges with net/netip
- Listing interfaces and addresses
- Reading service banners from permitted lab targets
- Short task: a DNS report for a list of domains
TLS and secure connections
- Client and certificate verification with crypto/tls
- A TLS server and a secure configuration
- Inspecting certificates with x509 and expiry warnings
- Mutual TLS: authenticating with client certificates
- A simple TCP proxy and io.Copy
- Short task: check the certificate expiry of the lab servers
Capstone
- Capstone: a reachability and TLS report for the services in the lab network
Practice labs
- Reading a greeting line with net.Dial: Connect to a service on the lab target with net.Dial, read the first line and close the connection on every path.
- A concurrent line-transforming server: Write a TCP server that handles each connection in its own goroutine, upper-cases each line and writes it back, closing the listener cleanly on shutdown.
- A line-based chat room: Write a server that broadcasts messages to everyone in the room where a slow client does not stall others and a departing client's goroutine does not leak.
- A UDP echo client and server: Write a UDP server that returns datagrams and a client that waits for the reply with a read deadline.
- Reading length-prefixed messages: Read messages carrying a four-byte length prefix with io.ReadFull and return an error without allocating for a message over the maximum size.
- Cutting off a slow peer with deadlines: Add read, write and idle deadlines to a server whose goroutines are exhausted by a client dripping data so the goroutine count stays flat under the load test.
- Finding whether an address is in an allowed range: Write a function that classifies addresses as private, loopback or inside the allowed lab range with net/netip.
- A DNS report for a list of domains: Send A, AAAA, MX and TXT queries to the lab resolver with net.Resolver, apply a timeout per name and mark not-found separately.
- Collecting greeting lines from allow-listed targets: Connect only to allow-listed lab addresses with a concurrency limit and timeouts, refuse targets off the list and write the greeting lines as JSON.
- Finding the days left on a certificate: Connect to the lab TLS target, read the server certificate's expiry date and return the days remaining.
- Making the client trust the internal CA: Fix a client running with InsecureSkipVerify by using a root pool containing the lab's internal CA and show a wrongly named server is rejected.
- Inspecting a certificate chain and raising warnings: Inspect the chains of the lab servers with x509 and raise separate warnings for certificates with under thirty days left, weak keys and name mismatches.
- Setting the minimum version on a TLS server: Set up a TLS server with a prepared certificate, make the minimum version 1.2 and test that a client using an older version is refused.
- Mutual authentication with client certificates: Configure the server to accept only client certificates signed by the internal CA and pass the name in the certificate to the handler.
- Handling half-close correctly in a TCP proxy: Remove the goroutine left hanging when one side closes in a proxy copying both directions with io.Copy and pass the leak test with CloseWrite and deadlines.
About this course
You write TCP and UDP clients and servers with the net package, resolve DNS, set deadlines and TLS correctly and build reliable network tools in your own lab network.
What you will learn
- TCP and UDP
- Name resolution and network info
- TLS and secure connections
- Capstone
Prerequisites
You should be comfortable with the level 101 and 201 topics of the same path.
Lab environment
Lessons run in your own Kali Linux terminal in the browser, connected to a private lab network. Nothing to install.
Frequently asked questions
- Is this course right for my level?
- The course is at level 301; it assumes you know the topics of the lower-level courses.
- Is there anything to install?
- No. Every lesson runs in your own lab environment that opens in the browser.
- How do lessons work?
- Each lesson has 8 to 10 steps and a short quiz. Early steps show the command to type, later steps give less help; if two attempts fail, the solution opens.
- Can I try it for free?
- Yes. The first three lessons of every course are free.