0

Is there a way / is it possible to execute the unix whois query using php, possibly using system().?

I am trying

echo '<pre>';
$last_line = system('whois ryansmurphy.com', $retval);
echo '
</pre>
<hr />Last line of the output: ' . $last_line . '
<hr />Return value: ' . $retval;

but it doesnt work. what am i doing wrong?

Am seeing nothing, no errors, no output.

RSM
  • 14,540
  • 34
  • 97
  • 144
  • 1
    That should work, what's your question? Maybe it's not working because you're using backticks instead of quotes? – Mike B Jan 31 '13 at 19:33
  • @sorry for poor explanation. See update – RSM Jan 31 '13 at 19:35
  • What doesn't work? What output/errors are you seeing? What are you trying to do? – Mike B Jan 31 '13 at 19:36
  • check if `$last_line` is false. if it is, the command failed. – Amelia Jan 31 '13 at 19:43
  • Do you get a result when you run `passthru('whois ryansmurphy.com');` ? – Ryan Jan 31 '13 at 19:45
  • return value was commented out and i uncomment it and it returns 127? does anyone know what this means – RSM Jan 31 '13 at 19:50
  • 127 means command not found. recompose your code as `system('/path/to/dir/with/whois ryansmurphy.com', $retval);` Good luck. – shellter Jan 31 '13 at 21:03
  • Do not go to the shell to start a whois command from your PHP program. Use the specific libraries that you have in your language to do whois queries or just read RFC3912 on whois and open a TCP socket on port 43 to send your request terminated by CR + LF – Patrick Mevzek Jan 03 '18 at 21:52

2 Answers2

0

Use

exec($command, $output, $exit_code);

Where:

$command - your command ("whois ...")

$output - command output.

$exit_code - command exit code

exec command PHP

Reut Sharabani
  • 30,449
  • 6
  • 70
  • 88
0

If the command is not returning anything, then it is most likely returning an error to standard error, which isn't being captured. Try adding 2>&1 to send the errors to standard out.

$last_line = system('whois ryansmurphy.com 2>&1', $retval);

This is covered in the PHP Manual for system() and exec()