{"id":23871432,"url":"https://github.com/knotsphp/publicip","last_synced_at":"2026-03-27T04:30:24.680Z","repository":{"id":263192695,"uuid":"889574045","full_name":"knotsphp/publicip","owner":"knotsphp","description":"Fast and reliable way to get your public IP address with PHP","archived":false,"fork":false,"pushed_at":"2025-04-07T07:10:48.000Z","size":53,"stargazers_count":47,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-03-17T11:12:15.559Z","etag":null,"topics":["api","dig","dns","php","whoami"],"latest_commit_sha":null,"homepage":"https://srwiez.com/open-source","language":"PHP","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/knotsphp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"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":"SRWieZ"}},"created_at":"2024-11-16T17:13:18.000Z","updated_at":"2026-01-26T10:11:16.000Z","dependencies_parsed_at":"2024-11-20T13:15:20.181Z","dependency_job_id":"00dbf973-0635-4537-baef-4c249a5a1045","html_url":"https://github.com/knotsphp/publicip","commit_stats":null,"previous_names":["srwiez/native-myip","knotsphp/publicip"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/knotsphp/publicip","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knotsphp%2Fpublicip","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knotsphp%2Fpublicip/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knotsphp%2Fpublicip/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knotsphp%2Fpublicip/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/knotsphp","download_url":"https://codeload.github.com/knotsphp/publicip/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knotsphp%2Fpublicip/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31019237,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-27T03:51:26.850Z","status":"ssl_error","status_checked_at":"2026-03-27T03:51:09.693Z","response_time":164,"last_error":"SSL_read: 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","dig","dns","php","whoami"],"created_at":"2025-01-03T14:58:35.573Z","updated_at":"2026-03-27T04:30:24.599Z","avatar_url":"https://github.com/knotsphp.png","language":"PHP","funding_links":["https://github.com/sponsors/SRWieZ"],"categories":[],"sub_categories":[],"readme":"# PublicIP\n[![Latest Stable Version](https://poser.pugx.org/knotsphp/publicip/v)](https://packagist.org/packages/knotsphp/publicip) \n[![Total Downloads](https://poser.pugx.org/knotsphp/publicip/downloads)](https://packagist.org/packages/knotsphp/publicip) \n[![Latest Unstable Version](https://poser.pugx.org/knotsphp/publicip/v/unstable)](https://packagist.org/packages/knotsphp/publicip) \n[![License](https://poser.pugx.org/knotsphp/publicip/license)](https://packagist.org/packages/knotsphp/publicip) \n[![PHP Version Require](https://poser.pugx.org/knotsphp/publicip/require/php)](https://packagist.org/packages/knotsphp/publicip) \n[![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/knotsphp/publicip/test.yml?label=Tests)](https://github.com/knotsphp/publicip/actions/workflows/test.yml)\n\nA simple PHP library to get your public IP address reliably and fast.\n\nThis library uses `dig` or HTTP requests to obtain the public IP address of the current machine by utilizing publicly\navailable whoami services.\n\nIt comes with an opinionated default configuration to use the **fastest** and most **reliable** fetchers and providers.\nHowever, it also includes a flexible API that allows you to use different fetchers and different providers.\n\n## 🚀 Installation\n\n```bash\ncomposer require knotsphp/publicip\n```\n\n## 📚 Usage\n\nEasiest way to get the public IP address of the current machine is to use the `PublicIP::get()` method.\n\n```php\nuse KnotsPHP\\PublicIP\\Finders\\{ PublicIP, PublicIPv4, PublicIPv6 };\n\n$ipv4 = PublicIPv4::get(); // returns your IPv4\n$ipv6 = PublicIPv6::get(); // returns your IPv6\n$ipv4or6 = PublicIP::get(); // returns either IPv4 or IPv6\n```\nThese methods return the IP address as a `string` or `null` if the fetcher fails. No exceptions are thrown.\n\nIf you want to use a specific fetcher, or a specific provider, you can use the `PublicIPv4::finder()-\u003efetch()` method.\n\n```php\nuse KnotsPHP\\PublicIP\\Enums\\DnsProvider;\nuse KnotsPHP\\PublicIP\\Fetchers\\DigFetcher;\nuse KnotsPHP\\PublicIP\\Finders\\PublicIPv4;\n\n$ipv4 = PublicIPv4::finder()\n    -\u003eaddFetcher((new DigFetcher())\n        -\u003efrom(DnsProvider::OpenDNS)))\n    -\u003efetch();\n```\nThis method gives you more control, but you will need to manage exceptions on your own.\n\n### Advanced Usage\n\nYou can also use a `Fetcher` directly to get the IP address.\n\n```php\nuse KnotsPHP\\PublicIP\\Enums\\DnsProvider;\nuse KnotsPHP\\PublicIP\\Enums\\IpVersion;\nuse KnotsPHP\\PublicIP\\Fetchers\\DigFetcher;\n\n$ipv4 = (new DigFetcher)-\u003efrom(DnsProvider::Cloudflare)-\u003efetch(IpVersion::v4);\n```\n\nNote that this returns null instead of throwing an exception if the fetcher fails.\n\n## 📚 Use in command line\n\nYou can also use this library in the command line by using the `publicip` command.\n\nIt's recommended to install the library globally to use it in the command line.\n```bash\ncomposer global require knotsphp/publicip\n```\n\nThen you can use the `publicip` command to get the public IP address of the current machine.\n```bash\n# In your project directory\nvendor/bin/publicip\n\n# Globally installed\npublicip\n\n# To get the IPv4 address\npublicip --ipv4\npublicip -4\n\n# To get the IPv6 address\npublicip --ipv6\npublicip -6\n```\n\n## 🏃 Performance\n\nIf you are sure that your machine has `dig` installed, you can speed up the process by setting the `isSupported`\nproperty to `true`.\n\nIt works both ways; if you are sure that your machine does not have `dig` installed, you can set it to `false` to\nprevent unnecessary checks.\n\n```php\nuse KnotsPHP\\PublicIP\\Fetcher\\DigFetcher;\n\nDigFetcher::$isSupported = true;\n```\n\nIf you use the `CurlFetcher` or `FileGetContentsFetcher`, you can set the `forceHTTP` property to `true` to use HTTP instead of HTTPS.\nSome whoami services do not support HTTPS anyway as they are meant to be used in scripts like this `curl ifconfig.co`.\n\n```php\nuse KnotsPHP\\PublicIP\\Fetcher\\CurlFetcher;\nuse KnotsPHP\\PublicIP\\Fetchers\\FileGetContentsFetcher;\n\nCurlFetcher::$forceHTTP = true;\nFileGetContentsFetcher::$forceHTTP = true;\n```\n\n## 📖 Documentation\n\n`dig` provider list\n\n|            | IP4or6 | IPv4 | IPv6 | Reliable?                                                                              |\n|------------|--------|------|------|----------------------------------------------------------------------------------------|\n| Cloudflare | ✅      | ✅    | ✅    | ✅                                                                                      |\n| Google     | ✅      |      |      | ✅                                                                                      |\n| OpenDNS    | ✅      | ✅    | ✅    | ⚠️ says they have blocked France \u0026 Portugal but seems to work in France in my testings |\n| Akamai     | ⚠️     | ⚠️   | ⚠️   | ⚠️ last digits of the IP can be wrong                                                  |\n\nHTTP whoami provider list\n\n|                | IPv4 | IPv6 | IP4or6 | Note          |\n|----------------|------|------|--------|---------------|\n| ifconfig.co    | ✅    | ✅    | ✅      | Fast          |\n| ipify.org      | ✅    | ✅    | ✅      | Open-source   |\n| ifconfig.me    | ✅    | ✅    | ✅      |               |\n| icanhazip.com  | ✅    | ✅    | ✅      |               |\n| cloudflare.com | ✅    | ✅    | ✅      | Use more data |\n| ipinfo.io      | ✅    |      |        | ⚠️ only IPv4  |\n| amazonaws.com  | ✅    |      |        | ⚠️ only IPv4  |\n\n## 📋 TODO\nContributions are welcome!\n\n- use Symfony ExecutableFinder to find dig\n- use Symfony Process to run dig\n- PSR-18 HTTP fetcher with a way to choose psr compatible client so other tools can monitor outgoing requests\n\n## 🤝 Contributing\nClone the project and run `composer update` to install the dependencies.\n\nBefore pushing your changes, run `composer qa`. \n\nThis will run [pint](http://github.com/laravel/pint) (code style), [phpstan](http://github.com/phpstan/phpstan) (static analysis), and [pest](http://github.com/pestphp/pest) (tests).\n\n## 📦 Alternatives\n\nIf you are not pleased with this library, check out the following alternatives:\n\n- https://github.com/martinlindhe/php-myip\n\nYou can also contribute to this library by opening an issue or a pull request.\n\n## 👥 Credits\n\nPublicIP was created by Eser DENIZ.\n\n## 📝 License\n\nPublicIP is licensed under the MIT License. See LICENSE for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fknotsphp%2Fpublicip","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fknotsphp%2Fpublicip","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fknotsphp%2Fpublicip/lists"}