net/public-ip.py
The host's public IPv4/IPv6 address as the internet sees it, from ifconfig.me (no API key) -- what `curl ifconfig.me` prints, as a fraglet so a workflow can record where it ran. Prints the bare address and nothing else.
Use when the user asks what their public IP is, or a workflow needs the address it is running from -- for example to locate itself with net/ip-location.py.
- the file
- net/public-ip.py
- its skill
- net/SKILL.md (the whole net pack)
- as knowledge
- okf/net/public-ip.md
- on GitHub
- net/public-ip.py ↗
Run it
1. Once per machine: install fragletc (Docker must already be running).
curl -fsSL https://raw.githubusercontent.com/ofthemachine/fraglet/main/install.sh | sh
2. Fetch the tool and print its contract.
curl -fsSLO https://tools.ofthemachine.com/net/public-ip.py && chmod +x public-ip.py && ./public-ip.py --fraglet-help
3. Run it.
./public-ip.py
Parameters
| name | type | requirement | description |
|---|---|---|---|
| none | |||
Outputs
stdout
Provenance
- image
- ofthemachine/python3@sha256:a015b4f9f0e7c1648f8fcd4164f6a296dd3c9189404f88f333a9764d08d13522
- reach
network=required— output depends on live external state; do not cache indefinitely.- procedure_hash
- sha256:d71f3629175b487624acc6086f2561641680b39c7f8cc34b2436e9f44f6c6396
- receipt
- add
--receipt run.jsonto any run;receipt/attest.pyverifies it against this hash without re-running.
Source
public-ip.py · 20 lines · sha256 d71f3629175b…
#!/usr/bin/env -S fragletc --image ofthemachine/python3@sha256:a015b4f9f0e7c1648f8fcd4164f6a296dd3c9189404f88f333a9764d08d13522
#: d=The host's public IPv4/IPv6 address as the internet sees it, from ifconfig.me (no API key) -- what `curl ifconfig.me` prints, as a fraglet so a workflow can record where it ran. Prints the bare address and nothing else.
#: when=Use when the user asks what their public IP is, or a workflow needs the address it is running from -- for example to locate itself with net/ip-location.py.
#: network=required
#: stdin=none
import sys
import urllib.request
req = urllib.request.Request("https://ifconfig.me/ip", headers={"User-Agent": "curl"})
try:
with urllib.request.urlopen(req, timeout=15) as resp:
ip = resp.read().decode("ascii", "replace").strip()
except Exception as e:
print(f"ip lookup failed: {e}", file=sys.stderr)
sys.exit(1)
if not ip or " " in ip:
print(f"unexpected response: {ip!r}", file=sys.stderr)
sys.exit(1)
print(ip)