Find NameServers of Domain Using PHP Shell Command

Share this Article
Reading Time: 3 minutes
168 Views

Inside this article we will see the concept i.e Find NameServers of Domain Using PHP Shell Command. Article contains the classified information about Retrieving the name servers of a given domain with PHP.

There are several ways to get Nameservers of any domain. But in this tutorial we will see the use of PHP function shell_exec(). This is a very simple concept to learn and get to your code implementation.

Learn More –

Let’s get started.

Check Domain Nameservers Using Terminal

Open system terminal and run this command.

$ whois onlinewebtutorblog.com | grep "Name Server"

Output

Let’s see in PHP programming.

Application Programming

Create a folder with name php-ns.

Next, create a file index.php inside it.

Open index.php and write this complete code into it.

<?php

$whois = shell_exec('whois onlinewebtutorblog.com | grep "Name Server"');

$NsString = str_replace("Name Server: ", " ", $whois);

//echo $NsString;

echo "<pre>";

$NsArray = explode(" ", strtolower($NsString));

print_r(array_filter($NsArray));

Before running this shell command in your PHP environment, you need to make sure these:

  • shell_exec should be enabled
  • whois package should be available in your system

Output

We hope this article helped you to learn about Find NameServers of Domain Using PHP Shell Command in a very detailed way.

Buy Me a Coffee

Online Web Tutor invites you to try Skillshike! Learn CakePHP, Laravel, CodeIgniter, Node Js, MySQL, Authentication, RESTful Web Services, etc into a depth level. Master the Coding Skills to Become an Expert in PHP Web Development. So, Search your favourite course and enroll now.

If you liked this article, then please subscribe to our YouTube Channel for PHP & it’s framework, WordPress, Node Js video tutorials. You can also find us on Twitter and Facebook.

Was this post helpful?

Get PHP Web Development Courses on Offer in just ₹299
Get PHP Web Development Courses on Offer in just ₹299