Python Testing Connectivity: ping, nc, traceroute & nslookup
Network diagnostics in Unix rely on specialized tools: `ping` tests ICMP round-trip latency and packet loss; `nc` (netcat) tests raw TCP/UDP port connectivity; `traceroute` maps network hop routing; and `dig`/`nslookup` query DNS name servers.
"`ping` is like shouting "Marco!" and waiting for "Polo!" across the canyon; `nc` is checking if a specific door in a building is unlocked; `dig` is looking up an address in the global postal directory."
Deep Dive: How It Works
ping -c Count: On Unix, ping runs infinitely unless limited with `-c <count>` (e.g. `ping -c 4 8.8.8.8`).
Netcat Port Probing (-z -v): `nc -zv host.com 443` tests if a remote port is accepting connections without sending payload.
DNS Inspection: `dig +short domain.com` extracts resolved IP records cleanly for scripting.
Syntax Blueprint
ping -c 3 1.1.1.1 # ICMP test (3 packets) nc -zv -w 3 api.domain.com 443 # TCP port check with 3s timeout dig +short google.com A # Fast DNS resolution
Use ping -c for latency tests, nc -zv for port checks, and dig for DNS records.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Assuming a service is down because `ping` fails.Why it happens: Modern firewalls frequently drop ICMP Echo requests by security policy.
How to fix: Test the actual TCP application port using `nc -zv <host> <port>` or `curl -I`.
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Ping Loopback with Count Limit
Run `ping -c 1 127.0.0.1` to send a single packet to the local interface.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.