Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <form action="dns.php" method="POST">
- Hostname: <input type="text" name="host" />
- Type: <select name="type">
- <option value="a">A</option>
- <option value="mx">MX</option>
- <option value="ns">NS</option>
- <option value="txt">TXT</option> </select>
- <input type="submit" name="submit" value="Submit" />
- </form>
- <?
- if(!empty($_POST['host']) && !empty($_POST['type'])){
- // Grab variable from form and define valid types
- $host = $_POST['host'];
- $type = strtoupper($_POST['type']);
- $validtypes=array("A","MX","NS","TXT");
- // Check that dns type is defined or allowed
- if(!defined("DNS_" . $type) or !in_array($type,$validtypes)){
- echo "Invalid DNS Type!";
- }else{
- $type = constant("DNS_" . $type);
- $rec = dns_get_record($host, $type);
- // Set result types - can be modified by using available elements from $rec array
- switch($type){
- case DNS_A:
- $recvals=array("Hostname" => "host","Type" => "type", "IP" => "ip");
- break;
- case DNS_MX:
- $recvals=array("Hostname" => "host","Type" => "type", "Target" => "target", "Priority" => "pri");
- break;
- case DNS_NS:
- $recvals=array("Hostname" => "host","Type" => "type", "Target" => "target");
- break;
- case DNS_TXT:
- $recvals=array("Hostname" => "host","Type" => "type", "Record" => "txt");
- break;
- }
- // Output results
- foreach ($rec as $arr => $num){
- foreach ($recvals as $title => $value){
- echo $title . " : " . $num[$value] . "\n";
- }
- }
- }
- } else {
- echo "Either hostname or record type is missing";
- }
Add Comment
Please, Sign In to add comment