Solved

Create/delete DNS records from php

Posted on 2011-03-14
6
355 Views
Last Modified: 2012-05-11
Hi,
We already have in place a solution for quering DNS reocrds and creating/deleting DNS records.
It was developed earlier last year when I was a trainee :)
I think we make it a little better at this time.
Here are the few important questions that I would like to ask you exparts in this regards,
1. Can we query the whole windows DNS from php directly?
2. Can we create/delete DNS records from php directly?
I know that we can do NS lookup from single IP/host but not sure about whole DNS
Also I remeber that when I was developing it, we could create DNS records from php but I think there some internal security procedures that I couldnt get that to work.
Just hoping that dsome one owuld bge able to help me out with it i.e questions 1 and 2.
Thanks for ur help.
0
Comment
Question by:SameerMirza
  • 3
  • 3
6 Comments
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 35129559
You would need to tell us a lot more about the DNS records in question, but....

1. If the DNS records are 'local' ie hosted on your server then you can update them by writing the relevant config files in the approriate folder, but you say it is a windows machine and I've never seen a Windows machine being used as a DNS server

2. If the server is remote but you have access to it then you can create a passwordless login key to allow the use of rsync to read/write the DNS conf files, but you will need to have a way to issue the BIND server a "reload" instruction of else the changed will not take effect

3. If the server is remote and you have no access to then you will need to use an API to access it. Many hosting companies release their own API and sometimes their own scripts for doing the update.

Finally, you say "I think we make it a little better at this time." My reaction is to say "if it works ok then don't fiddle with it". Improving code is often a route to hardship and working code is better in many respects than 'perfect' code that causes a lot of work for little payback.
0
 

Author Comment

by:SameerMirza
ID: 35129686
ok. But the existing process drop a file which is then picked up by a batch script that uses dnscmd to create/delete entries.
I can provide further detail if you think its worth improving it.? But yes it works perfactly fine. Specially if we can create it directly from php.
Yes, we can access the remote dns server and I am pretty sure its windows based.
Just one question. I have changed the confirmation to be based on ns lookup for which I am using gethostbyaddr()
this function return the hostname if the entry exists. And returns the IP itself if it doesnt
So I keep the check based on this function.
If it return the host on creation -> I assume entry has been created
and if it reuturns the IP itself I accume that the entry has not been created.
Just wanted to confirm if there a ny better lookup procedure or this is ok?
I fire it straight on the DC that we create record on so its almost instant.
0
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 35129842
By the sound of what you are describing, you are creating a text file which PHP can easily generate for you via fopen() or file_put_contents()  

http://www.php.net/fopen
http://www.php.net/file_put_contents

"I have changed the confirmation to be based on ns lookup for which I am using gethostbyaddr()"

As far as I recall gethostbyaddr() will use whatever nameserver the system it is running on uses. As long as you are sure that the nameserver service you use provides an accurate reflection of the server in question then you should be OK.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:SameerMirza
ID: 35130024
bportlock,
Thanks for your help. I ment to say that we already have the functionality in place based on text files generated by php and the batch script to process them. - CURRENT FUNCTINALITY
Yes, I am aware of the nameserver the system is using and we are creating the records on the same server.
So thanks for confirming that.
The actualy question is that do you think we should try and improve it or not?
I think I already know your answer on it but may be it would be good to know. :)

thanks again
0
 
LVL 34

Accepted Solution

by:
Beverley Portlock earned 500 total points
ID: 35130099
"The actualy question is that do you think we should try and improve it or not?"

No. Not unless you need to add a feature that is needed and is completely missing or if you have a broken feature that does not work

Try Googling "If it ain't broke don't fix it"  http://lmgtfy.com/?q=If+it+ain%27t+broke+don%27t+fix+it
0
 

Author Closing Comment

by:SameerMirza
ID: 35130255
:) I am sure it would be helpful for many
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Occasionally you run into the website or two that will not resolve properly using your own DNS servers.  Some people simply set up global forwarders for their DNS server.  I don’t recommend doing this because it can cause problems resolving addresse…
Learn about cloud computing and its benefits for small business owners.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now