{"id":48578033,"url":"https://github.com/virtualox/myip-examples","last_synced_at":"2026-04-08T16:04:00.076Z","repository":{"id":325947472,"uuid":"1095988314","full_name":"virtualox/myip-examples","owner":"virtualox","description":"Code examples and integration guides for myip.foo - Free, privacy-focused IP lookup API. No auth required. Python, JavaScript, Bash, Go, PHP, Ruby, Rust examples.","archived":false,"fork":false,"pushed_at":"2025-11-24T11:00:32.000Z","size":22,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-28T00:47:18.387Z","etag":null,"topics":["api-client","api-examples","bash-scripts","code-examples","developer-tools","free-api","ip-address","ip-lookup","ipv4","ipv6","javascript-examples","networking-tools","python-examples","rest-api","vpn-checker"],"latest_commit_sha":null,"homepage":"https://myip.foo/api-docs.html","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/virtualox.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":["virtualox"],"custom":["https://paypal.me/VirtualOx"]}},"created_at":"2025-11-13T19:36:32.000Z","updated_at":"2025-11-24T11:00:36.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/virtualox/myip-examples","commit_stats":null,"previous_names":["virtualox/myip-examples"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/virtualox/myip-examples","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/virtualox%2Fmyip-examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/virtualox%2Fmyip-examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/virtualox%2Fmyip-examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/virtualox%2Fmyip-examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/virtualox","download_url":"https://codeload.github.com/virtualox/myip-examples/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/virtualox%2Fmyip-examples/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31562697,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T14:31:17.711Z","status":"ssl_error","status_checked_at":"2026-04-08T14:31:17.202Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-client","api-examples","bash-scripts","code-examples","developer-tools","free-api","ip-address","ip-lookup","ipv4","ipv6","javascript-examples","networking-tools","python-examples","rest-api","vpn-checker"],"created_at":"2026-04-08T16:03:59.827Z","updated_at":"2026-04-08T16:04:00.067Z","avatar_url":"https://github.com/virtualox.png","language":null,"readme":"# MyIP.foo API Examples\n\n**Code examples and integration guides for [myip.foo](https://myip.foo) - a free, privacy-focused IP lookup API**\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![API Status](https://img.shields.io/badge/API-Live-brightgreen)](https://myip.foo/api)\n[![No Auth Required](https://img.shields.io/badge/Auth-None%20Required-blue)](https://myip.foo/api-docs)\n\n---\n\n## 🚀 Quick Start\n\n**Get your IP in one line:**\n\n```bash\n# Plain text\ncurl https://myip.foo/plain\n\n# JSON with geolocation\ncurl https://myip.foo/api\n```\n\n**No API key required. No registration needed. 100% free.**\n\n---\n\n## 📚 What is MyIP.foo?\n\n[MyIP.foo](https://myip.foo) is a fast, privacy-focused IP address lookup service built on Cloudflare Workers. It provides:\n\n- ✅ **Dual-stack support** - Dedicated IPv4 and IPv6 endpoints\n- ✅ **Geolocation data** - City, country, ISP, timezone, coordinates\n- ✅ **No logging** - Your IP is never stored\n- ✅ **Free API** - JSON and plain text endpoints\n- ✅ **GDPR compliant** - Full privacy compliance\n- ✅ **Lightning fast** - \u003c50ms response time (edge computing)\n\n---\n\n## 📖 API Endpoints\n\n### `/plain` - Plain Text\n\nReturns only your IP address as plain text.\n\n**Response:**\n```\n2001:db8::1\n```\n\n**Perfect for:**\n- Shell scripts\n- CI/CD pipelines\n- Docker healthchecks\n- Quick IP lookups\n\n---\n\n### `/api` - JSON API\n\nReturns comprehensive IP information in JSON format including connection type detection (VPN/Datacenter/Residential).\n\n**Response:**\n```json\n{\n  \"ip\": \"2001:db8::1\",\n  \"type\": \"IPv6\",\n  \"location\": {\n    \"country\": \"NL\",\n    \"city\": \"Amsterdam\",\n    \"region\": \"North Holland\",\n    \"postalCode\": \"1012\",\n    \"timezone\": \"Europe/Amsterdam\",\n    \"latitude\": \"52.3740\",\n    \"longitude\": \"4.8897\"\n  },\n  \"network\": {\n    \"asn\": 1136,\n    \"isp\": \"KPN B.V.\"\n  },\n  \"cloudflare\": {\n    \"colo\": \"AMS\",\n    \"ray\": \"7d4f1a2b3c4d5e6f-AMS\"\n  }\n}\n```\n\n---\n\n### `/headers` - HTTP Headers\n\nReturns all HTTP headers sent by your browser.\n\n**Response:**\n```json\n{\n  \"headers\": {\n    \"user-agent\": \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)...\",\n    \"accept\": \"text/html,application/xhtml+xml...\",\n    \"accept-language\": \"en-US,en;q=0.9\",\n    \"accept-encoding\": \"gzip, deflate, br\"\n  }\n}\n```\n\n**Perfect for:**\n- Debugging HTTP headers\n- Browser fingerprinting research\n- Testing proxy/VPN header leaks\n\n---\n\n### `/user-agent` - User Agent String\n\nReturns your browser's User-Agent string as plain text.\n\n**Response:**\n```\nMozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36\n```\n\n**Perfect for:**\n- Quick browser identification\n- Testing User-Agent spoofing\n- CI/CD browser detection\n\n---\n\n### `/api/connection-type` - Connection Type Detection\n\nDetects if your connection is from a VPN, datacenter, or residential network.\n\n**Response:**\n```json\n{\n  \"ip\": \"1.2.3.4\",\n  \"connectionType\": \"datacenter\",\n  \"provider\": \"Hetzner Online GmbH\",\n  \"asn\": 24940\n}\n```\n\n**Possible values:**\n- `residential` - Home/mobile ISP\n- `datacenter` - Hosting provider, VPS\n- `vpn` - Known VPN provider (via Tor exit nodes database)\n- `unknown` - Unable to determine\n\n**Perfect for:**\n- VPN detection\n- Fraud prevention\n- Traffic analysis\n\n---\n\n### Dual-Stack Endpoints\n\nCheck IPv4 and IPv6 connectivity separately using dedicated subdomains:\n\n| Endpoint | Returns | DNS Record |\n|----------|---------|------------|\n| `https://ipv4.myip.foo/ip` | IPv4 address only | A record |\n| `https://ipv6.myip.foo/ip` | IPv6 address only | AAAA record |\n\n```bash\n# Check IPv4\ncurl -s https://ipv4.myip.foo/ip\n# Output: 203.0.113.42\n\n# Check IPv6\ncurl -s https://ipv6.myip.foo/ip\n# Output: 2001:db8::1\n```\n\n**Perfect for:**\n- Dual-stack connectivity testing\n- Network diagnostics\n- CI/CD environment checks\n\n---\n\n## 📁 Example Files\n\nThis repository includes ready-to-use example scripts in the `/examples` directory:\n\n### Bash\n- **[dual-stack-check.sh](examples/bash/dual-stack-check.sh)** - Check IPv4 and IPv6 connectivity\n\n### Python\n- **[dual-stack-check.py](examples/python/dual-stack-check.py)** - Parallel dual-stack check with connection type detection\n\n### React / TypeScript\n- **[useMyIP.ts](examples/react/useMyIP.ts)** - React hooks: `useMyIP()`, `useMyIPDualStack()`, `useMyIPPlain()`\n\n### GitHub Actions\n- **[check-runner-ip.yml](examples/github-actions/check-runner-ip.yml)** - Get runner IP, check dual-stack, deploy with IP whitelisting\n\n### Monitoring\n- **[ip-change-alert.py](examples/monitoring/ip-change-alert.py)** - Monitor IP changes with Slack/Discord webhooks\n\n---\n\n## 💻 Code Examples\n\n### Bash / curl\n\n```bash\n# Get your IP address\ncurl https://myip.foo/plain\n\n# Save to variable\nMY_IP=$(curl -s https://myip.foo/plain)\necho \"My IP: $MY_IP\"\n\n# Force IPv4\ncurl -4 https://myip.foo/plain\n\n# Force IPv6\ncurl -6 https://myip.foo/plain\n\n# Get JSON data\ncurl -s https://myip.foo/api | jq '.'\n\n# Extract specific field\ncurl -s https://myip.foo/api | jq -r '.location.country'\n\n# Get User-Agent\ncurl https://myip.foo/user-agent\n\n# Get all headers\ncurl -s https://myip.foo/headers | jq '.'\n\n# Check connection type\ncurl -s https://myip.foo/api/connection-type | jq '.'\n```\n\n---\n\n### Python\n\n```python\nimport requests\n\n# Get IP as string\nip = requests.get('https://myip.foo/plain').text.strip()\nprint(f\"My IP: {ip}\")\n\n# Get full data\ndata = requests.get('https://myip.foo/api').json()\nprint(f\"IP: {data['ip']}\")\nprint(f\"Country: {data['location']['country']}\")\nprint(f\"City: {data['location']['city']}\")\nprint(f\"ISP: {data['network']['isp']}\")\n```\n\n**VPN Verification:**\n```python\nimport requests\n\ndef check_vpn_status():\n    data = requests.get('https://myip.foo/api').json()\n    expected_country = \"NL\"  # Netherlands\n    actual_country = data['location']['country']\n\n    if actual_country == expected_country:\n        print(f\"✅ VPN active: {data['ip']} ({data['location']['city']}, {actual_country})\")\n    else:\n        print(f\"⚠️  VPN inactive or wrong location: {actual_country}\")\n\ncheck_vpn_status()\n```\n\n---\n\n### JavaScript / Node.js\n\n```javascript\n// Using fetch (Node.js 18+)\nconst response = await fetch('https://myip.foo/api');\nconst data = await response.json();\n\nconsole.log(`IP: ${data.ip}`);\nconsole.log(`Location: ${data.location.city}, ${data.location.country}`);\nconsole.log(`ISP: ${data.network.isp}`);\n\n// Plain text\nconst ip = await fetch('https://myip.foo/plain').then(r =\u003e r.text());\nconsole.log(`My IP: ${ip.trim()}`);\n```\n\n---\n\n### PHP\n\n```php\n\u003c?php\n// Get IP as string\n$ip = file_get_contents('https://myip.foo/plain');\necho \"My IP: \" . trim($ip);\n\n// Get JSON data\n$data = json_decode(file_get_contents('https://myip.foo/api'), true);\necho \"IP: \" . $data['ip'] . \"\\n\";\necho \"Country: \" . $data['location']['country'] . \"\\n\";\necho \"City: \" . $data['location']['city'] . \"\\n\";\n?\u003e\n```\n\n---\n\n### Go\n\n```go\npackage main\n\nimport (\n    \"encoding/json\"\n    \"fmt\"\n    \"io\"\n    \"net/http\"\n)\n\ntype IPData struct {\n    IP       string `json:\"ip\"`\n    Location struct {\n        Country string `json:\"country\"`\n        City    string `json:\"city\"`\n    } `json:\"location\"`\n}\n\nfunc main() {\n    // Plain text\n    resp, _ := http.Get(\"https://myip.foo/plain\")\n    body, _ := io.ReadAll(resp.Body)\n    fmt.Printf(\"My IP: %s\\n\", string(body))\n\n    // JSON\n    resp, _ = http.Get(\"https://myip.foo/api\")\n    var data IPData\n    json.NewDecoder(resp.Body).Decode(\u0026data)\n    fmt.Printf(\"%s from %s, %s\\n\", data.IP, data.Location.City, data.Location.Country)\n}\n```\n\n---\n\n### Ruby\n\n```ruby\nrequire 'net/http'\nrequire 'json'\n\n# Get IP as string\nip = Net::HTTP.get(URI('https://myip.foo/plain')).strip\nputs \"My IP: #{ip}\"\n\n# Get JSON data\nuri = URI('https://myip.foo/api')\nresponse = Net::HTTP.get(uri)\ndata = JSON.parse(response)\nputs \"IP: #{data['ip']}\"\nputs \"Country: #{data['location']['country']}\"\n```\n\n---\n\n### Rust\n\n```rust\nuse reqwest;\nuse serde::Deserialize;\n\n#[derive(Deserialize)]\nstruct Location {\n    country: String,\n    city: String,\n}\n\n#[derive(Deserialize)]\nstruct IPData {\n    ip: String,\n    location: Location,\n}\n\n#[tokio::main]\nasync fn main() -\u003e Result\u003c(), Box\u003cdyn std::error::Error\u003e\u003e {\n    // Plain text\n    let ip = reqwest::get(\"https://myip.foo/plain\")\n        .await?\n        .text()\n        .await?;\n    println!(\"My IP: {}\", ip.trim());\n\n    // JSON\n    let data: IPData = reqwest::get(\"https://myip.foo/api\")\n        .await?\n        .json()\n        .await?;\n    println!(\"{} from {}, {}\", data.ip, data.location.city, data.location.country);\n\n    Ok(())\n}\n```\n\n---\n\n## 🛠️ Use Cases\n\n### 1. IP Change Monitor\n\n```bash\n#!/bin/bash\n# check-ip.sh - Monitor IP changes\n\nIP_FILE=\"/tmp/current_ip.txt\"\nCURRENT_IP=$(curl -s https://myip.foo/plain)\n\nif [ -f \"$IP_FILE\" ]; then\n  OLD_IP=$(cat \"$IP_FILE\")\n  if [ \"$OLD_IP\" != \"$CURRENT_IP\" ]; then\n    echo \"IP changed: $OLD_IP → $CURRENT_IP\"\n    # Send notification here\n  fi\nfi\n\necho \"$CURRENT_IP\" \u003e \"$IP_FILE\"\n```\n\n### 2. GitHub Actions - Get Runner IP\n\n```yaml\nname: Check Runner IP\non: [push]\njobs:\n  check-ip:\n    runs-on: ubuntu-latest\n    steps:\n      - name: Get GitHub Actions runner IP\n        run: |\n          IP=$(curl -s https://myip.foo/plain)\n          echo \"Runner IP: $IP\"\n          curl -s https://myip.foo/api | jq '.'\n```\n\n### 3. Docker Healthcheck\n\n```dockerfile\nHEALTHCHECK --interval=30s --timeout=3s \\\n  CMD curl -f https://myip.foo/plain || exit 1\n```\n\n### 4. VPN Connection Checker\n\n```python\nimport requests\nimport sys\n\ndef verify_vpn(expected_country):\n    data = requests.get('https://myip.foo/api').json()\n    actual_country = data['location']['country']\n\n    if actual_country == expected_country:\n        print(f\"✅ VPN connected to {actual_country}\")\n        sys.exit(0)\n    else:\n        print(f\"❌ VPN failed - Location: {actual_country} (expected {expected_country})\")\n        sys.exit(1)\n\n# Usage: python vpn-check.py NL\nif __name__ == \"__main__\":\n    expected = sys.argv[1] if len(sys.argv) \u003e 1 else \"US\"\n    verify_vpn(expected)\n```\n\n### 5. Firewall Whitelist Helper\n\n```bash\n#!/bin/bash\n# whitelist-current-ip.sh - Add current IP to firewall\n\nCURRENT_IP=$(curl -s https://myip.foo/plain)\necho \"Adding $CURRENT_IP to firewall whitelist...\"\n\n# AWS Security Group example\naws ec2 authorize-security-group-ingress \\\n  --group-id sg-xxxxx \\\n  --protocol tcp \\\n  --port 22 \\\n  --cidr \"$CURRENT_IP/32\"\n\necho \"✅ $CURRENT_IP whitelisted for SSH access\"\n```\n\n---\n\n## 🔒 Privacy\n\n- ✅ **No logging** - Your IP address is NOT stored\n- ✅ **No tracking** - No cookies, no user accounts\n- ✅ **GDPR compliant** - Full EU privacy compliance\n- ✅ **Open source** - Transparent code\n\nSee our [Privacy Policy](https://myip.foo/privacy.html) for details.\n\n---\n\n## 📖 Full Documentation\n\nFor complete API documentation, visit [myip.foo/api-docs](https://myip.foo/api-docs.html).\n\n---\n\n## 🤝 Contributing\n\nFound a bug or want to add an example? PRs are welcome!\n\n1. Fork this repository\n2. Create your feature branch (`git checkout -b feature/amazing-example`)\n3. Commit your changes (`git commit -m 'Add Python async example'`)\n4. Push to the branch (`git push origin feature/amazing-example`)\n5. Open a Pull Request\n\n---\n\n## 📝 License\n\nMIT License - see [LICENSE](LICENSE) file for details.\n\n---\n\n## 💖 Support\n\nIf you find MyIP.foo useful, consider:\n\n- ⭐ Starring this repository\n- 🐦 Sharing on social media\n- ☕ [Buying us a coffee](https://paypal.me/VirtualOx)\n\n---\n\n## 🔗 Links\n\n- **Website:** [myip.foo](https://myip.foo)\n- **API Docs:** [myip.foo/api-docs](https://myip.foo/api-docs.html)\n- **About:** [myip.foo/about](https://myip.foo/about.html)\n- **Issues:** [GitHub Issues](https://github.com/virtualox/myip-examples/issues)\n\n---\n\n## 🏢 About\n\nMyIP.foo is built by [JustFox](https://justfox.dev) (VirtualOx B.V.), an app development company focused on privacy-first, open-source solutions.\n\n---\n\n**Built with ❤️ by JustFox 🦊**\n","funding_links":["https://github.com/sponsors/virtualox","https://paypal.me/VirtualOx"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvirtualox%2Fmyip-examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvirtualox%2Fmyip-examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvirtualox%2Fmyip-examples/lists"}