0

As a service, we would like to have on our website the ability for visitors to put in a domain name to see who owns it. I know there are other services on the web to do this for whois, but we would like to offer this on our own website.

How can this be done in PHP? I am aware of the whois linux shell command, but I want to be able to interface with this directly through PHP so I can cleanly return who owns the domain. THanks!

This should not be closed and it isn't a duplicate question. None of the others allow to easily parse the owner of a domain. Just barfing back a loose format of output isn't helpful. That's the same reason I'm not using a shell script for this. Thank you for paying attention!

Edward
  • 9,430
  • 19
  • 48
  • 71
  • Why can't you use `whois` with PHP. There are a few commands in PHP that let you execute commandline utilities... `exec()` and `system()` for example... – Lix May 09 '13 at 06:10
  • Try http://www.internoetics.com/2010/01/12/simple-whois-php-script/ and http://www.nott.org/blog/php-whois-script.html .. Hope it helps.. – Hiren Pandya May 09 '13 at 06:15
  • None of those solutions allow to easily parse the domain's owner. – Edward May 09 '13 at 06:48
  • I can do here perfectly. What is the point? Of course the results of a whois differ ... but the label REGISTRANT is always present, then all you need is find out what the results bellow this label. Use regex to do it. – devasia2112 May 09 '13 at 08:44
  • This website uses PHP that parses whois data https://whoownsthedomain.com/ – Rivers Nov 28 '17 at 00:48

2 Answers2

0

if you know the shell command, you can just use exec() of php, you can read about it here but make sure that you put the full path to the command, php not allways configured like the command line to 'see' the bin folder

Dima
  • 8,586
  • 4
  • 28
  • 57
  • This is the worst advice to give. Do not shell out from PHP just to run a whois command. Use the appropriate PHP libraries or read RFC3912 for Whois Protocol Specification and just open a TCP socket to port 43. – Patrick Mevzek Jan 03 '18 at 20:21
  • So u want to wrap the shell command with a 3rd party library just to say its better? – Dima Jan 13 '18 at 15:46
  • This is absolutely not what I said. Use a proper whois library that will open a TCP socket on port 43 or do open it yourself. You do not need to go to the shell to send an external command just to open a TCP socket. Of course using a library that does the shell escape for you is as bad as doing it yourself, or just slightly better (if it tries at least to impose some security measures but performance wise it will be as bad). – Patrick Mevzek Jan 13 '18 at 20:05
  • at the time this was asked, thats was ok. you are digging a question that is 5 years old. – Dima Jan 14 '18 at 20:35
  • No, it was not right then, it is not right now, and will never be right in the future. Do not shell out from your program to run a shell command if 1) you have libraries doing everything or 2) the command is so simple you just need to open a tcp socket like for `whois`. – Patrick Mevzek Jan 14 '18 at 21:18
  • ok, i will not run a shell command if i have library that is doing it with a shell command. great... – Dima Jan 15 '18 at 09:46
  • Please try to read what I write: "Of course using a library that does the shell escape for you is as bad as doing it yourself" – Patrick Mevzek Jan 15 '18 at 13:06
  • so u dig into every library u use? – Dima Jan 16 '18 at 12:08
  • sorry, but i like to move fast with development. – Dima Jan 16 '18 at 12:08
  • A program is written once, read many times, executed even more times. I let you conclude which part is better to optimize. – Patrick Mevzek Jan 17 '18 at 01:22
  • 1
    the part when you write super optimized code and go public after 2 years, when 10 other companies already did IPO with your idea.... – Dima Jan 23 '18 at 06:50
-2

With whois you will get what you want.

whois yourdomain.tld | tail -60

or

whois yourdomain.tld | grep "Registrant" >> /home/user/varlog.log

The above command will output in your shell the last 60 lines, you optionally can write it to a log, the name of REGISTRANT is in the first line of the output in some cases, or whatever it is, just output REGISTRANT to a log, if the information of registrant is in only one line, then you can create a condition to verify it, and output N lines after registrant is found. Then in php you can create some regex to capture what information is in need.

P.s.: If you log the output then you can read it with PHP.

devasia2112
  • 5,844
  • 6
  • 36
  • 56
  • The output for that looks ugly. Also, whois on shell's output isn't always the same. Try whois for google.com and a bunch of junk comes up which doesn't have the domain's owner. That's why I'm looking for this to be done through PHP hopefully with a more direct interface to the fields returned. Thanks! – Edward May 09 '13 at 06:52
  • There are nothing you can do with PHP! But with tools that you can call using PHP to interface the results. Sorry to disappoint you. – devasia2112 May 09 '13 at 08:03
  • Do not shell out from PHP just to run a whois command. Use the appropriate PHP libraries or read RFC3912 for Whois Protocol Specification and just open a TCP socket to port 43. – Patrick Mevzek Jan 03 '18 at 20:21