1. Go to this page and download the library: Download knotsphp/publicip library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
knotsphp / publicip example snippets
use KnotsPHP\PublicIP\Finders\{ PublicIP, PublicIPv4, PublicIPv6 };
$ipv4 = PublicIPv4::get(); // returns your IPv4
$ipv6 = PublicIPv6::get(); // returns your IPv6
$ipv4or6 = PublicIP::get(); // returns either IPv4 or IPv6
use KnotsPHP\PublicIP\Enums\DnsProvider;
use KnotsPHP\PublicIP\Fetchers\DigFetcher;
use KnotsPHP\PublicIP\Finders\PublicIPv4;
$ipv4 = PublicIPv4::finder()
->addFetcher((new DigFetcher())
->from(DnsProvider::OpenDNS)))
->fetch();
use KnotsPHP\PublicIP\Enums\DnsProvider;
use KnotsPHP\PublicIP\Enums\IpVersion;
use KnotsPHP\PublicIP\Fetchers\DigFetcher;
$ipv4 = (new DigFetcher)->from(DnsProvider::Cloudflare)->fetch(IpVersion::v4);
use KnotsPHP\PublicIP\Fetcher\DigFetcher;
DigFetcher::$isSupported = true;
use KnotsPHP\PublicIP\Fetcher\CurlFetcher;
use KnotsPHP\PublicIP\Fetchers\FileGetContentsFetcher;
CurlFetcher::$forceHTTP = true;
FileGetContentsFetcher::$forceHTTP = true;
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.