Overview
When running APITHON in Gateway mode, you must choose between two network scopes:- Localhost (L) - API accessible only from the host machine (
127.0.0.1) - LAN (N) - API accessible from any device on your local network (
0.0.0.0)
Network configuration only applies to Gateway Mode. Chat Mode runs locally without network exposure.
Network Selection Menu
After choosing Gateway Mode (Option 1), you’ll see the network configuration prompt:apithon.py:195-208
Input Validation
The selection loop validates your input and repeats until you enter a valid option:apithon.py:195-208
Localhost Mode (L)
How It Works
When you select L, APITHON starts the Flask server bound to the loopback interface:bind_all=False:
host = "127.0.0.1"display_ip = "127.0.0.1"
apithon.py:163-167
Use Cases
Personal Development
Testing scripts and automation tools on the same machine
Maximum Security
No network exposure - impossible to access remotely
No Firewall Issues
Bypasses all firewall rules since traffic never leaves the host
Single-User Workflows
When you only need to run queries from the host machine
Example Commands
The tutorial displays commands using127.0.0.1:
LAN Mode (N)
How It Works
When you select N, APITHON binds to all network interfaces and detects your LAN IP:bind_all=True:
host = "0.0.0.0"- Listens on all network interfacesdisplay_ip = get_lan_ip()- Detects and displays your private IP
apithon.py:163-167
IP Detection Mechanism
APITHON automatically discovers your LAN IP address:- Creates a UDP socket (no actual data transmitted)
- “Connects” to Google’s DNS server (8.8.8.8:80)
- Retrieves the local socket address used for routing
- Returns the IP address, or falls back to
127.0.0.1on failure
apithon.py:43-51
Use Cases
Multi-Device Access
Access the API from phones, tablets, or other computers on your network
Team Collaboration
Multiple users in the same office/home can share one gateway instance
IoT Integration
Connect embedded devices or smart home systems to the API
Testing Distributed Systems
Test how different services interact with the API across the network
Example Commands
The tutorial displays commands using your detected LAN IP (e.g.,192.168.1.45):
Testing LAN AccessFrom another device on your network:
- Note the IP displayed in the APITHON tutorial (e.g.,
192.168.1.45) - Use that IP in place of
localhostor127.0.0.1 - Ensure both devices are on the same subnet
- Verify firewall rules allow incoming connections on port 5000
Security Considerations
Authentication
APITHON implements basic Bearer token authentication:UnHackerEnCapital (defined at apithon.py:29)
Best Practices
Use Strong API Keys
Use Strong API Keys
- Change the default API key before deploying in LAN mode
- Use a randomly generated string with high entropy
- Consider using environment variables:
API_KEY_GATEWAY = os.getenv("APITHON_KEY", "fallback")
Network Isolation
Network Isolation
- Only use LAN mode on trusted networks (home/office)
- Avoid using LAN mode on public WiFi or shared networks
- Consider using a separate VLAN for security testing tools
Audit Access
Audit Access
- Monitor Flask logs for unexpected API calls
- Implement request logging to track who’s accessing the gateway
- Consider adding IP whitelisting for production use
Terminate When Not in Use
Terminate When Not in Use
- Don’t leave the gateway running indefinitely
- Use Ctrl+C to properly shut down when finished
- Remember: the session data remains in memory while running
Firewall Configuration
Port Requirements
APITHON uses port 5000 for the Flask server (hardcoded inapithon.py:167).
Windows Firewall
If you’re running in LAN mode on Windows and other devices can’t connect:Linux Firewall (UFW)
Linux Firewall (firewalld)
Network Topology Examples
Localhost Architecture
LAN Architecture
Troubleshooting Connection Issues
Can't Connect from Another Device (LAN Mode)
Can't Connect from Another Device (LAN Mode)
Checklist:
-
Verify you selected ‘N’ (LAN mode)
- If you selected ‘L’ by mistake, restart and choose ‘N’
-
Confirm both devices are on the same network
- Check firewall rules (see Firewall Configuration section above)
-
Verify the gateway is running
-
Test with curl from the client device
Connection Works Locally but Not from LAN
Connection Works Locally but Not from LAN
This indicates a firewall issue on the host machine.Quick test:If this fails, your firewall is blocking loopback connections.
If this succeeds, the firewall is only blocking external connections.→ Follow the Firewall Configuration section to open port 5000.
Wrong IP Address Displayed
Wrong IP Address Displayed
If Use the correct IP when accessing from other devices, even if the tutorial shows the wrong one.
get_lan_ip() returns 127.0.0.1 or an unexpected address:Cause: Multiple network interfaces or no default route to internetSolution:Port 5000 Already in Use
Port 5000 Already in Use
Error message:
Address already in useSolution:Performance Considerations
Localhost vs LAN Latency
Localhost
- Latency: Less than 1ms (loopback interface)
- Bandwidth: Virtually unlimited (no physical network)
- Reliability: 100% (no network interference)
LAN
- Latency: 1-5ms (typical home WiFi)
- Bandwidth: Limited by network speed (WiFi ~100-1000 Mbps)
- Reliability: Can be affected by network congestion
Flask Threading Model
Flask’s development server (used in APITHON) handles requests sequentially by default:Summary
| Aspect | Localhost (L) | LAN (N) |
|---|---|---|
| Bind Address | 127.0.0.1 | 0.0.0.0 |
| Accessibility | Host machine only | All devices on network |
| Security | Maximum (no network exposure) | Moderate (requires API key) |
| Firewall | No configuration needed | May require firewall rules |
| IP Detection | Static 127.0.0.1 | Dynamic via get_lan_ip() |
| Use Case | Personal development | Multi-device access |
| Tutorial IP | Always 127.0.0.1 | Detected LAN IP (e.g., 192.168.1.45) |
Recommendation
- Development/Testing: Use Localhost (L) for maximum security and simplicity
- Team Collaboration: Use LAN (N) when multiple devices need access
- Always change the default API key in production scenarios