Reverse lookup

Issues related to applications and software problems
Post Reply
drodriguez
Posts: 1
Joined: 2016/09/20 15:10:17

Reverse lookup

Post by drodriguez » 2016/09/20 15:42:31

I made couple scripts to created the RPT or reverse lookup. I'm not a programmer or scripting expert but the script help to me create the RPT. Remember run in you own risk. And modify the script according with you needs.
*** First bash to create the A records it extracts the A records from zone file. sort the records in sortarecords.dat. Remember to change the file zone and create empty files arecords.dat / sortarecords.dat


# lee archivo de registro y crea archivo ordenado por IP
#!/bin/sh

cat YOUR_FILE_ZONE | awk '{if ($2 == "A" && (substr($1,1,1)!=";") && (substr($1,1,1)!="#") ) print $1,$2,$3}' > arecords.dat
sort -u -k3 -V arecords.dat > sortarecords.dat

**** second script in PHP to create the reverse lookup. It read the sort file created in the firts scripts.
#scipts para crear los archivo necesarios para los reverse lookup.


$D= date("Ymd");
$nfile = "sortarecords.dat";
$afile = file($nfile);
# ********* IMPORTANT CHANGE TO YOU FILE PATH ***************
$path = "/xxxx/xxxxx/";
$IN = "IN";
$PRT = "PRT";
$T = '$TTL';
$R= "01";
$TTL = "$T 86400\n";
#*************** chango to you primary dns **************
$DNS = "123.123.123.1\n";
$INSOA = "@ IN SOA yourdomian. yourdomain. (\n";
$DAC = "; yyyymmddss\n";
$DAR = " $D$R ; serial number\n";
$RFT = " 10800 ; refresh after 3 hours\n";
$RAT = " 3600 ; retry after 1 hour\n";
$EPT = " 604800 ; expire after 1 week\n";
$MIT = " 86400 ) ; minimum TTL of 1 day\n\n";
# ************ CHANGE TO YOUR DOMAIN **********
$NS = " $IN NS dns.YOURDOMAIN.edu\n\n";
$COMEN = ";\n; Zone NS records\n;\n";

foreach ($afile as $aline) {
$ip = trim(substr(strrchr($aline, ' '), 1));
$DOM = explode(" ",$aline);
$DOMI = $DOM[0];
$ips = explode(".",$ip);
$pips = "$ips[0].$ips[1].$ips[2]";
$xarp = "$ips[0].$ips[1].$ips[2].arp";
$file = "$path/$xarp";
if (file_exists( "$file")){
$INAIP = " {$IN} A {$DNS}\n";
$RPRT = "{$ips[3]} {$IN} {$PRT} {$DOMI}\n";
file_put_contents($file, $RPRT, FILE_APPEND | LOCK_EX);}
else{
$new_file = "$file";
$INAIP = " {$IN} A {$DNS}\n";
$RPRT = "{$ips[3]} {$IN} {$PRT} {$DOMI}\n";
file_put_contents($file, $RPRT, FILE_APPEND | LOCK_EX);
$new_file = "$file";
$handle = fopen($new_file, 'w') or die('Cannot open file: '.$new_file); //implicitly creates file
file_put_contents($new_file, $TTL, FILE_APPEND | LOCK_EX);
file_put_contents($new_file, $INSOA, FILE_APPEND | LOCK_EX);
file_put_contents($new_file, $DAC, FILE_APPEND | LOCK_EX);
file_put_contents($new_file, $DAR, FILE_APPEND | LOCK_EX);
file_put_contents($new_file, $RFT, FILE_APPEND | LOCK_EX);
file_put_contents($new_file, $RAT, FILE_APPEND | LOCK_EX);
file_put_contents($new_file, $EPT, FILE_APPEND | LOCK_EX);
file_put_contents($new_file, $MIT, FILE_APPEND | LOCK_EX);
file_put_contents($new_file, $INAIP, FILE_APPEND | LOCK_EX);
file_put_contents($new_file, $COMEN, FILE_APPEND | LOCK_EX);
file_put_contents($new_file, $NS, FILE_APPEND | LOCK_EX);
file_put_contents($new_file, $RPRT, FILE_APPEND | LOCK_EX);
}}


?>

Post Reply