Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #38: add *.ir ccSLD domains #39

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
composer.lock
/vendor
/.buildpath
/.project
/.settings
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,27 @@ if ($domain->isAvailable()) {
echo "Domain is registered\n";
}

```
```

A more complete example:

```php

<?php
require_once __DIR__.'/../vendor/autoload.php';

$sld = 'nabi.ir';

try {
$domain = new Phois\Whois\Whois($sld);
} catch (InvalidArgumentException $e) {
die($e->getMessage()."\n");
}

if ($domain->isAvailable()) {
echo "Domain is available\n";
} else {
echo "Domain is registered\n";
}

```
16 changes: 16 additions & 0 deletions examples/usage-example2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
require_once __DIR__.'/../vendor/autoload.php';

$sld = 'nabi.ir';

try {
$domain = new Phois\Whois\Whois($sld);
} catch (InvalidArgumentException $e) {
die($e->getMessage()."\n");
}

if ($domain->isAvailable()) {
echo "Domain is available\n";
} else {
echo "Domain is registered\n";
}
28 changes: 23 additions & 5 deletions src/Phois/Whois/Whois.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class Whois
private $subDomain;

private $servers;

private $whoisInfo;

/**
* @param string $domain full domain name (without trailing dot)
Expand All @@ -29,10 +31,19 @@ public function __construct($domain)
throw new \InvalidArgumentException("Invalid $domain syntax");
// setup whois servers array from json file
$this->servers = json_decode(file_get_contents( __DIR__.'/whois.servers.json' ), true);

if (!$this->isValid())
throw new \InvalidArgumentException("Domain name isn't valid!");
}


/**
* @param string, domain whois information
*/
public function info()
{
if ($this->whoisInfo != '')
return $this->whoisInfo;

if ($this->isValid()) {
$whois_server = $this->servers[$this->TLDs][0];

Expand Down Expand Up @@ -116,12 +127,13 @@ public function info()
$string_encoding = mb_detect_encoding($string, "UTF-8, ISO-8859-1, ISO-8859-15", true);
$string_utf8 = mb_convert_encoding($string, "UTF-8", $string_encoding);

return htmlspecialchars($string_utf8, ENT_COMPAT, "UTF-8", true);
$this->whoisInfo = htmlspecialchars($string_utf8, ENT_COMPAT, "UTF-8", true);
return $this->whoisInfo;
} else {
return "No whois server for this tld in list!";
}
} else {
return "Domainname isn't valid!";
return "Domain name isn't valid!";
}
}

Expand Down Expand Up @@ -153,10 +165,16 @@ public function getSubDomain()
{
return $this->subDomain;
}


/**
* @return boolean, true for domain avaliable, false for domain registered
*/
public function isAvailable()
{
$whois_string = $this->info();
if ($this->whoisInfo == '')
$whois_string = $this->info();
else
$whois_string = $this->whoisInfo;
$not_found_string = '';
if (isset($this->servers[$this->TLDs][1])) {
$not_found_string = $this->servers[$this->TLDs][1];
Expand Down
28 changes: 28 additions & 0 deletions src/Phois/Whois/whois.servers.json
Original file line number Diff line number Diff line change
Expand Up @@ -1491,6 +1491,34 @@
"whois.nic.ir",
"no entries found"
],
"co.ir": [
"whois.nic.ir",
"no entries found"
],
"ac.ir": [
"whois.nic.ir",
"no entries found"
],
"sch.ir": [
"whois.nic.ir",
"no entries found"
],
"id.ir": [
"whois.nic.ir",
"no entries found"
],
"gov.ir": [
"whois.nic.ir",
"no entries found"
],
"org.ir": [
"whois.nic.ir",
"no entries found"
],
"net.ir": [
"whois.nic.ir",
"no entries found"
],
"ru": [
"whois.ripn.net",
"No entries found"
Expand Down