A simple CLI tool that validates network connectivity before executing commands
ipsafe is a command-line tool that checks a network condition before executing any command. If the condition passes, it executes the command. If the condition fails, it blocks execution.
Default behavior: Fetches https://www.google.com and checks if the HTTP status code is 2xx.
npm install -g ipsafeSimply prefix any command with ipsafe:
# Check connectivity before npm install
ipsafe "npm install"
# Verify connection before git operations
ipsafe "git push origin main"
# Safe API calls
ipsafe "curl https://api.example.com/data"
# Configuration commands
ipsafe --init # Setup global config
ipsafe --config # Show current config
ipsafe --help # Show help$ ipsafe "npm install"
π Checking network connectivity to https://www.google.com...
β
Network connectivity verified
π Executing: npm install
# ... npm install output (streamed in real-time)
β¨ Command completed successfullyVisual Features:
- π¨ Colorful output - Green for success, red for errors, cyan for info
- πΊ Real-time streaming - See command output as it happens
- π― Clear status indicators - Emojis and colors make status obvious
Create a global configuration that works everywhere:
# Create global config with defaults
ipsafe --init
# Check current configuration
ipsafe --config
# See where config file is located
ipsafe --config-pathipsafe follows standard configuration practices with this search order:
Priority 1 - Project Config (highest priority)
./ipsafe.config.json(current directory)
Priority 2 - Global User Config
- macOS/Linux:
~/.config/ipsafe/config.json - Windows:
%APPDATA%/ipsafe/config.json
Priority 3 - Simple Dotfile (fallback)
~/.ipsafe.json
Priority 4 - Built-in Defaults
{
"testUrl": "https://www.google.com",
"timeout": 3000,
"retries": 1,
"method": "GET",
"userAgent": "ipsafe/1.0.3",
"checkContent": false,
"searchText": null,
"searchType": "contains",
"headers": {},
"commandTimeout": 0
}β
Works everywhere - No need to create config in each project
β
Standard locations - Follows OS conventions (~/.config/)
β
Easy setup - One command creates global config
β
Flexible override - Project configs can override global settings
β
Portable - Sync via dotfiles across machines
| Option | Default | Description |
|---|---|---|
testUrl |
https://www.google.com |
URL to test connectivity against |
timeout |
3000 |
Request timeout in milliseconds |
retries |
1 |
Number of retry attempts |
method |
GET |
HTTP method to use |
userAgent |
ipsafe/1.0.3 |
User-Agent header |
checkContent |
false |
Enable content validation |
searchText |
null |
Text/pattern to search for in response |
searchType |
contains |
Search method: contains or regex |
headers |
{} |
Custom HTTP headers |
commandTimeout |
0 |
Command execution timeout in ms (0 = no timeout) |
- Condition Check: Makes HTTP request to configured URL
- Status Validation: Verifies HTTP status code is 2xx (200-299)
- Content Validation (optional): Searches for specific text/pattern in response
- Command Execution: If all checks pass, executes the provided command with real-time output
- Streaming Output: Shows command output as it happens (great for long-running commands)
- Signal Handling: Supports Ctrl+C to interrupt long-running commands
- Blocking: If any check fails, blocks command execution
# Uses default https://www.google.com check
ipsafe "npm install express"# Streaming output for long commands
ipsafe "ping -c 10 google.com"
# Works with any long-running command
ipsafe "npm run build"
ipsafe "docker build -t myapp ."
# Infinite commands (use Ctrl+C to stop)
ipsafe "ping google.com"
ipsafe "tail -f /var/log/system.log"# CLI tools with prompts (using --print for non-interactive)
ipsafe 'claude --print "What is 2+2?"'
# Piped input works too
echo "Explain Docker" | ipsafe "claude --print"
# Commands that need full terminal access
ipsafe "vim myfile.txt" # Opens vim with full TTY
ipsafe "htop" # Interactive process monitor{
"testUrl": "https://api.github.com"
}IPLocate (https://www.iplocate.io/) provides a free IP geolocation API that's perfect for personal daily usage. We thank IPLocate for offering this valuable service to the community!
To use IPLocate, you'll need to get a free API key from their website. They offer generous free quotas that should cover most personal usage needs.
{
"testUrl": "https://iplocate.io/api/lookup?apikey=<your_api_key>",
"method": "GET",
"checkContent": true,
"searchText": "ip",
"searchType": "contains",
"headers": {
"Accept": "application/json"
}
}This configuration will:
- Check connectivity by querying your current IP information
- Validate that the response contains IP data
- Only execute your command if the API responds correctly
Replace <your_api_key> with your actual API key from IPLocate.
{
"testUrl": "https://httpbin.org/json",
"checkContent": true,
"searchText": "\"slideshow\".*\"title\"",
"searchType": "regex"
}{
"testUrl": "https://api.private.com/health",
"headers": {
"Authorization": "Bearer your-api-key",
"Accept": "application/json"
},
"checkContent": true,
"searchText": "healthy"
}The tool considers the condition successful when:
- HTTP status code is 2xx (200-299)
- Response is received within timeout period
- No network errors occur
- Content validation passes (if enabled)
The tool considers the condition failed when:
- HTTP status code is not 2xx
- Request times out
- Network errors (DNS resolution, connection refused, etc.)
- Content validation fails (if enabled)
- All retry attempts are exhausted
git clone <repository-url>
cd ipsafe
npm install
npm test # Run tests
npm run lint # Run linterMIT Β© nocoo
Have you ever started a long-running command only to realize you're offline? ipsafe prevents this frustration by checking connectivity first.
Perfect for:
- π Remote work with unstable connections
βοΈ Working while traveling- π CI/CD pipelines requiring network validation
- π‘οΈ Any script that depends on internet connectivity