Networking functions for connectivity checks, IP operations, DNS queries, and HTTP requests
The net module provides comprehensive networking utilities for checking connectivity, working with IP addresses, performing DNS queries, and making HTTP requests.
Different functions require different tools (curl/wget, nc, dig/nslookup). Functions gracefully degrade and provide helpful error messages when tools are missing.
Wait until a port is open (useful for service readiness).
# Wait for database to be readyif net::port::wait "localhost" 5432 30; then echo "Database is ready"else echo "Database failed to start within 30 seconds"fi
Parameters:
host - Hostname or IP address
port - Port number
timeout - Maximum wait time in seconds (default: 30)
interval - Check interval in seconds (default: 1)
Returns: Exit code 0 if port opens within timeout
net::port::scan(host, [start_port], [end_port])
Scan a range of ports and print open ones.
# Scan common portsnet::port::scan "localhost" 1 1024# Scan specific rangenet::port::scan "192.168.1.1" 8000 9000
Parameters:
host - Hostname or IP address
start_port - First port to scan (default: 1)
end_port - Last port to scan (default: 1024)
Returns: List of open ports (one per line)
Scanning large port ranges can be slow. Use responsibly.
source compiled.sh# Check internet connectivityif net::is_online; then echo "Internet connection: OK" # Get IP addresses local_ip=$(net::ip::local) public_ip=$(net::ip::public) echo "Local IP: $local_ip" echo "Public IP: $public_ip" # Check if IP is private if net::ip::is_private "$local_ip"; then echo "Using private network" fi # DNS lookup github_ip=$(net::resolve "github.com") echo "GitHub resolves to: $github_ip" # Check if service is available if net::port::is_open "github.com" 443; then echo "GitHub HTTPS is accessible" fielse echo "No internet connection"fi# Wait for local service to startecho "Starting database..."if net::port::wait "localhost" 5432 30; then echo "Database is ready"else echo "Database failed to start" exit 1fi