12.14
Well, to start with, apologies for the title line… why is everything abbreviated when it comes to computers? I guess it can’t do my SEO work any harm, right?
Anyway, back to something meaningful.
I’ve begun writing a little DNS Manager in PHP, that runs on an IIS 6/7 web server. Initially i was going to write this in .NET as it has alot of support for WMI out of the box, using the ManagementObject classes. But i work in ASP.NET for 40 hours (at least) a week, i like to play with different languages. (IIS 7 + Windows Server 2008 + PHP 5Â – http://www.waxer.nl/?p=72)
So, first off, how do we use COM in PHP? Fairly straight forward it would appear.
<?php $comObject = new COM ("WbemScripting.SWbemLocator"); ?>
Thats it. I now have a COM object loaded up into my variable. It’s nice to see that it’s just as easy if i was using say VBScript to accomplish this task.
So, now i want to connect to the DNS Service, so that i can list all of the zones i currently have setup. Again, a resonably simple task, using my above $comObject i can connect, and iterate through all DNS Zones.
<?php /*Connect to the DNS Server, first param is the Host, second is the Namespace, third is the username, fourth is the password (the last two are only required for a remote machine)*/ $dnsService = $comObject->ConnectServer('localhost', 'rootMicrosoftDNS', '', ''); //Loop through every instance of the class MicrosoftDNS_Zone in our DNS Service. foreach ($dnsService->InstancesOf("MicrosoftDNS_Zone") as $existingZone) { //For now, just echo it's name, just so we can see what Zones we have setup. echo 'Zone Name: ' . $existingZone->Name; } ?>
And thats, it, this is how we can show all of the zones inside a Microsoft DNS Server.
As you can see, we call an InstancesOf method inside our $dnsService variable, this does exactly what it says on the tin. It returns an array of ALL the specified instances inside this object. Which is great, because we can also call the same method to return all instances of A Records, or SOA Records. Which is very handy for writing a DNS Management portal!
The MicrosoftDNS_Zone is a class, that is provided by the WMI service in WIndows, if you follow the link provided, you can see all of it’s members, these are ALL fields we can view. You will also notice that the MicrosoftDNS_Zone class has a number of methods available to it too.
I will provide another blog on how to create/delete zones in your Microsoft DNS Server!
No Comment.
Add Your Comment