diff --git a/DOC/AGENT_Context_Project.md b/DOC/AGENT_Context_Project.md index ca3f153..330e7d5 100644 --- a/DOC/AGENT_Context_Project.md +++ b/DOC/AGENT_Context_Project.md @@ -34,7 +34,7 @@ Linux_post_install/ │ ├── bin/ # CLI tools — installed to /usr/local/bin/ │ ├── pos # Main dispatcher — smart arg matching to pos-* scripts -│ ├── pos-network-ip # Show interfaces, routes, public IP +│ ├── pos-network-ip # Show interfaces, routes, public IP + location │ ├── pos-network-checkport # TCP port checker │ ├── pos-network-scan # Parallel ping sweep of CIDR subnet │ ├── pos-docker-ps # Enhanced docker ps (health, IPs, ports, uptime) @@ -196,7 +196,7 @@ All non-interactive `pos` commands log output to `~/.local/share/linux_post_inst | Category | Command | Script | Description | |----------|---------|--------|-------------| -| network | ip | `pos-network-ip` | Show interfaces, routes, public IP | +| network | ip | `pos-network-ip` | Show interfaces, routes, public IP + location | | network | checkport | `pos-network-checkport` | Check TCP port connectivity | | network | scan | `pos-network-scan` | Parallel ping sweep of CIDR | | docker | ps | `pos-docker-ps` | Enhanced container overview | diff --git a/DOC/POS.md b/DOC/POS.md index 0ab1153..9a39e7a 100644 --- a/DOC/POS.md +++ b/DOC/POS.md @@ -50,7 +50,7 @@ Every non-interactive `pos` invocation logs to `~/.local/share/linux_post_instal | Command | File | Purpose | Configuration | |---------|------|---------|---------------| -| `pos network ip` | `bin/pos-network-ip` | Show interfaces, default route, public IP | None. Public IP via `https://ifconfig.me` (5s timeout) | +| `pos network ip` | `bin/pos-network-ip` | Show interfaces, default route, public IP + location | None. Public IP via `https://ifconfig.me`; location via `ip-api.com` (5s timeouts) | | `pos network checkport ` | `bin/pos-network-checkport` | Check if a TCP port is open | None. Uses `/dev/tcp` with a 2s timeout; exit 0/1 via OPEN/CLOSED | | `pos network scan [--full] [--retries N]` | `bin/pos-network-scan` | Two-phase nmap scan | See below | | `pos network hotspot [cmd]` | `bin/pos-network-hotspot` | Wi-Fi hotspot via `create_ap` (CLI) or `wihotspot-gui` (GUI) | Uses the precompiled binaries from `x64_bin/`; see below | diff --git a/bin/pos-network-ip b/bin/pos-network-ip index a8bb242..90774ea 100755 --- a/bin/pos-network-ip +++ b/bin/pos-network-ip @@ -42,5 +42,27 @@ SEP echo "Public IP" SEP -curl -4 -s --max-time 5 https://ifconfig.me 2>/dev/null || echo "Unavailable" +PUBLIC_IP=$(curl -4 -s --max-time 5 https://ifconfig.me 2>/dev/null) || true + +if [ -n "${PUBLIC_IP:-}" ]; then + echo "$PUBLIC_IP" + GEO=$(curl -4 -s --max-time 5 "http://ip-api.com/json/${PUBLIC_IP}?fields=status,country,regionName,city,isp" 2>/dev/null) || true + if [ -n "${GEO:-}" ]; then + location=$(echo "$GEO" | python3 -c " +import sys, json +d = json.load(sys.stdin) +if d.get('status') == 'success': + print(f\"{d['city']}, {d['regionName']}, {d['country']} ({d['isp']})\") +" 2>/dev/null) || true + if [ -n "${location:-}" ]; then + printf "%-20s %s\n" "Location" "$location" + else + echo "Location: Unavailable" + fi + else + echo "Location: Unavailable" + fi +else + echo "Unavailable" +fi echo