I am quite new to PHP, but I am building myself a tool, to avoid checking domain information using multiple sites, and have everything by clicking once.
The issue that I have, is that I am trying to run whois command, which works, if I specify the IP address (writing the IP manually within the code), as when I try to insert a variable instead of the IP (what customer inputs via website is domain name, I get the IP (A record) from the domain, and try to use it with the whois command) grep seems to not work anymore.
My idea is to grep "descr" so to see, to which company the IP belongs to.
Examples when it works:
$Host = shell_exec("whois 141.136.44.163 | grep 'descr'");
echo "<pre>$Host</pre>"
Output:
descr: Hostinger International Ltd. descr: HOSTINGER LT
As when I try to use a variable, which I get from the domain name with this command line:
$outputA = shell_exec("dig +short a $Domain");
And I use it for the whois:
$Host = shell_exec("whois $outputA | grep 'descr'");
The answer I receive from whois is the whole informarion, like you would run a command without grep: (whois IP:address)
It seems that grep isn't working anymore due to that. And I get something like this:enter image description here
Any idea how to fix this, or what could be causing this issue? Once I echo the whole whois command line with $outputA I receive a normal command line, which for example if I write to terminal, works without any issues (the IP from the $outputA is received, and grep is working via terminal).
For reference, my whole code:
$Domain = $_POST['DomainName'];
echo "DNS records for domain:", $Domain;
$outputNS = shell_exec("dig +short ns $Domain");
$outputA = shell_exec("dig +short a $Domain");
$outputMX = shell_exec("dig +short mx $Domain");
$outputTXT = shell_exec("dig +short txt $Domain");
echo "<pre>$outputNS</pre>";
echo "<pre>$outputA</pre>";
echo "<pre>$outputMX</pre>";
echo "<pre>$outputTXT</pre>";
$Registrar = shell_exec("whois $Domain | grep 'Registrar'");
$Host = shell_exec("whois $outputA | grep 'descr'");
echo "Original domain's Registrar:";
echo "<pre>$Registrar<pre>";
echo "<pre>$Host<pre>";