Find NameServers of Domain Using PHP Shell Command

Reading Time: 3 minutes
600 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.

Read More: Laravel How To Pass Multiple Parameters into Route Tutorial

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

Read More: How To Add Custom Attribute in Laravel Model Tutorial

Output

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

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.

Sanjay KumarHello friends, I am Sanjay Kumar a Web Developer by profession. Additionally I'm also a Blogger, Youtuber by Passion. I founded Online Web Tutor and Skillshike platforms. By using these platforms I am sharing the valuable knowledge of Programming, Tips and Tricks, Programming Standards and more what I have with you all. Read more