DaleSchool

Networking Tools

Beginner25min

Learning Objectives

  • Send HTTP requests and check responses with curl
  • Download files with wget
  • Check network connectivity with ping
  • Connect to remote servers with SSH

Working Code

Example 1: Checking connectivity with ping

ping google.com

Output:

PING google.com (142.250.206.46): 56 data bytes
64 bytes from 142.250.206.46: icmp_seq=0 ttl=116 time=12.345 ms
64 bytes from 142.250.206.46: icmp_seq=1 ttl=116 time=11.234 ms
^C
--- google.com ping statistics ---
2 packets transmitted, 2 packets received, 0.0% packet loss
  • icmp_seq: packet number (should be sequential; gaps mean packet loss)
  • time: response time (lower is better; under 100ms is normal)
  • packet loss: packet loss rate (0% is normal)

Press Ctrl+C to stop.

# Limit the number of pings
ping -c 4 google.com   # send only 4

Example 2: HTTP requests with curl

# Basic GET request
curl https://httpbin.org/get

Output (JSON):

{
  "headers": {
    "Host": "httpbin.org",
    "User-Agent": "curl/8.1.2"
  },
  "origin": "123.456.789.0",
  "url": "https://httpbin.org/get"
}
# Include response headers
curl -i https://httpbin.org/get

Output:

HTTP/2 200
content-type: application/json
...

{
  ...
}

Example 3: Downloading files

# Download with curl (-O: keep original filename)
curl -O https://example.com/file.txt

# Download with wget (curl alternative)
wget https://example.com/file.txt

Try It Yourself

curl: The Standard Tool for API Calls

# POST request (send JSON data)
curl -X POST https://httpbin.org/post \
  -H "Content-Type: application/json" \
  -d '{"name": "Alice", "age": 30}'

Output:

{
  "data": "{\"name\": \"Alice\", \"age\": 30}",
  "json": {
    "age": 30,
    "name": "Alice"
  }
}
# Check response code only
curl -o /dev/null -s -w "%{http_code}" https://google.com
# 200

# Add authorization header
curl -H "Authorization: Bearer YOUR_TOKEN" https://api.example.com/data

# Basic authentication
curl -u username:password https://api.example.com/protected

# Save response to a file
curl -o output.json https://api.example.com/data

# Follow redirects
curl -L https://bit.ly/shortlink

Common curl Options

| Option | Meaning | Example | | ------------- | --------------------------- | ------------------------------------- | | -X METHOD | HTTP method | -X POST, -X DELETE | | -H "header" | Add header | -H "Content-Type: application/json" | | -d "data" | Request body | -d '{"key":"value"}' | | -o filename | Save response | -o result.json | | -O | Save with original filename | (last part of URL) | | -s | Silent mode | (hide progress) | | -v | Verbose output | (for debugging) | | -L | Follow redirects | (follow redirects) | | -i | Include response headers | (include headers) |

wget: Dedicated Download Tool

# Basic download
wget https://example.com/archive.tar.gz

# Save with a different name
wget -O myfile.tar.gz https://example.com/archive.tar.gz

# Background download
wget -b https://example.com/large-file.iso

# Set retry count
wget --tries=5 https://example.com/file.txt

# Authenticated download
wget --user=username --password=password https://example.com/protected

# Mirror an entire website (offline use)
wget --mirror https://example.com

SSH: Remote Server Access

# Basic connection
ssh username@server-ip-or-hostname

# Specify port (default is 22)
ssh -p 2222 username@server.example.com

# Connect with an SSH key
ssh -i ~/.ssh/my-key.pem username@server.example.com

# Run a command on the remote server
ssh username@server "ls /var/www"

# Copy files (SCP)
scp local-file.txt username@server:/remote/path/
scp username@server:/remote/file.txt ./local/

# Copy directories
scp -r local-dir/ username@server:/remote/path/

Generating SSH Keys:

# Generate a key pair
ssh-keygen -t ed25519 -C "your@email.com"

# Generated files
ls ~/.ssh/
# id_ed25519     <- private key (never share!)
# id_ed25519.pub <- public key (register on servers)

# View public key contents
cat ~/.ssh/id_ed25519.pub

# Register public key on a server
ssh-copy-id username@server

"Why?" — Why Developers Need Networking Tools

| Scenario | Tool | | ------------------------- | ----------------- | | Test API behavior | curl | | Check server connectivity | ping | | Download files/software | wget, curl -O | | Server administration | ssh | | Transfer files to server | scp |

Real-world scenario: API testing

# Full REST API CRUD test
# Create
curl -X POST https://jsonplaceholder.typicode.com/todos \
  -H "Content-Type: application/json" \
  -d '{"title": "Add task", "completed": false}'

# Read
curl https://jsonplaceholder.typicode.com/todos/1

# Update
curl -X PUT https://jsonplaceholder.typicode.com/todos/1 \
  -H "Content-Type: application/json" \
  -d '{"id": 1, "title": "Updated task", "completed": true}'

# Delete
curl -X DELETE https://jsonplaceholder.typicode.com/todos/1

Common Mistakes

Mistake 1: Confusing -d and -H in curl

# Wrong: sending JSON without Content-Type
curl -X POST https://api.example.com/data \
  -d '{"key": "value"}'

# Correct: include Content-Type header
curl -X POST https://api.example.com/data \
  -H "Content-Type: application/json" \
  -d '{"key": "value"}'

Mistake 2: Sharing the SSH private key

# NEVER share this file
cat ~/.ssh/id_rsa      # private key! do not share

# This one is safe to share
cat ~/.ssh/id_rsa.pub  # public key (for server registration)

Mistake 3: Thinking the server is down because ping fails

Some servers block ping (ICMP) for security:

ping google.com   # Request timeout (server is actually up)

# Verify with a different method
curl -I https://google.com   # request HTTP headers only
# HTTP/1.1 301 -> actually working

Mistake 4: wget not available on macOS

macOS doesn't include wget by default:

wget file.txt
# zsh: command not found: wget

# Fix
brew install wget

# Or use curl instead
curl -O https://example.com/file.txt

Deep Dive

Measuring response time with curl
curl -o /dev/null -s -w "
    DNS lookup:     %{time_namelookup}s
    TCP connect:    %{time_connect}s
    TLS handshake:  %{time_appconnect}s
    First byte:     %{time_starttransfer}s
    Total time:     %{time_total}s
    Size:           %{size_download} bytes
" https://google.com

Useful for API performance testing and latency debugging.

SSH config file (~/.ssh/config)

Set up frequently accessed servers for convenience:

# ~/.ssh/config
Host myserver
    HostName 123.456.789.0
    User ubuntu
    IdentityFile ~/.ssh/my-key.pem
    Port 22

Host devserver
    HostName dev.example.com
    User developer
    Port 2222

After setup:

# Connect with a short alias
ssh myserver
scp file.txt myserver:/home/ubuntu/
Checking ports with netstat/lsof
# List open listening ports
lsof -i -P -n | grep LISTEN

# Find process using a specific port
lsof -i :3000
lsof -i :8080

# Network statistics on macOS
netstat -an | grep LISTEN
  1. Check response time to Google with ping -c 4 google.com.
  2. Send a GET request with curl https://httpbin.org/get and examine the response.
  3. Send a POST request with curl -X POST https://httpbin.org/post -H "Content-Type: application/json" -d '{"name":"test"}'.
  4. Check only the HTTP status code with curl -o /dev/null -s -w "%{http_code}" https://google.com.
  5. Generate an SSH key pair with ssh-keygen -t ed25519 -C "test@example.com" (skip if you already have one).

Q1. In curl -X POST -H "Content-Type: application/json" -d '{"key":"val"}' URL, which correctly describes each option?

  • A) -X POST: add header, -H: HTTP method, -d: specify URL
  • B) -X POST: HTTP method, -H: add header, -d: request body data
  • C) -X POST: save file, -H: specify host, -d: data format
  • D) -X POST: debug mode, -H: help, -d: specify domain